Working with CSV, JSON, Parquet & Excel
Read/write common file formats and choose Parquet for efficient columnar analytics storage.
In plain words
CSV and Excel are easy to open but slow and forgetful; Parquet is a faster, smaller format that remembers column types.
Think of it like…
Shipping goods: CSV is loose items in a box you must unpack and sort every time; Parquet is shrink-wrapped, labelled crates where you can pick just the columns you want without opening the rest.
Where you’ve seen it
A daily 2.1 GB events.csv takes 48 seconds to load and 4.5 GB of memory. After a one-time conversion with explicit dtypes to events.parquet (about 310 MB on disk), pd.read_parquet("events.parquet", columns=["user_id", "event_ts", "amount"]) loads only three columns in under 2 seconds, with timestamps already as datetimes.
Words you’ll hear
- Columnar storage
- Values stored column by column, so you read only what you need and compress well.
- dtype / usecols / chunksize
- read_csv options to set types, load some columns, or stream in pieces.
- json_normalize
- Flattens nested JSON records into columns.
- Schema
- Column names and types stored with a file (Parquet) rather than guessed.
Visual diagram
Theory & deep dive
Reading CSV, JSON and Excel reliably
pd.read_csv options solve most real files: sep=";" for other delimiters, encoding="utf-8-sig" or "latin-1" for encoding errors (a BOM or Windows files), na_values=[...] for placeholders, dtype={...} to keep IDs as strings, parse_dates=[...] for dates, usecols=[...] to read only some columns, nrows= to peek at big files, and on_bad_lines="skip" or "warn" for malformed rows. For files larger than memory, chunksize=500_000 yields DataFrames you can filter or aggregate piece by piece, or use Polars or DuckDB for out-of-core queries.
pd.read_json handles records and lines (lines=True for newline-delimited JSON), while nested structures need pd.json_normalize(data, record_path="items", meta=["order_id"]) to explode a list of line items into rows keeping parent fields. pd.read_excel(path, sheet_name="Sales", header=2, usecols="A:F") selects sheets and ranges; Excel files often have title rows, merged cells, totals rows and numbers stored as text, so inspect before trusting, and avoid Excel as a data store for anything automated.
df = pd.read_csv("events.csv", dtype={"user_id": "string"}, parse_dates=["event_ts"], na_values=["N/A", ""], usecols=["user_id", "event_ts", "amount"], encoding="utf-8-sig") fixes types and loads only needed columns.
Why and how to use Parquet
Parquet stores each column contiguously with its type and applies dictionary and run-length encoding plus compression (Snappy by default, Zstd for smaller files). Benefits: typically 5 to 10 times smaller than CSV, 10 to 50 times faster to read, columns can be selected (columns=[...]), filters can skip row groups (filters=[("event_date", ">=", "2026-11-01")]), and dtypes (including datetimes and categories) round-trip exactly. It works across pandas, Polars, DuckDB, Spark and warehouses.
Write with df.to_parquet("events.parquet", compression="zstd", index=False). For large, growing data, write a partitioned dataset (partition_cols=["event_date"]), so queries for one day read one folder. Parquet isn't human-readable and isn't designed for in-place updates; keep CSV or JSON for interchange and inspection, and use Parquet as the working format. Mind schema evolution: adding columns is fine, but changing a type across files requires care.
df.to_parquet("events.parquet", index=False) once, then pd.read_parquet("events.parquet", columns=["user_id", "amount"]) in every notebook, instead of re-parsing a 2 GB CSV each time.
How it works, step by step
Step 1 of 41. Peek before loading
Read a few rows or nrows to check delimiter, encoding, header and types.
- Look for
- encoding and bad lines
When to use it & trade-offs
What it is
Pandas reads and writes the formats data arrives in: CSV (read_csv), JSON (read_json, json_normalize for nested records), Excel (read_excel, needs openpyxl) and Parquet (read_parquet, needs pyarrow). CSV and JSON are text, row-oriented and untyped; Parquet is binary, columnar, compressed and typed, so it's smaller, much faster to read and keeps dtypes. Good practice is to accept messy inputs at the edge, convert once, and store the cleaned data as Parquet.
Why it matters: Reading a 2 GB CSV repeatedly in every notebook wastes minutes and loses types (dates become strings, IDs become floats). Choosing formats well speeds up analysis by an order of magnitude, shrinks storage and avoids repeating parsing bugs. Encoding errors, delimiters, bad lines and Excel quirks are everyday problems with simple fixes.
When to reach for it
- Parquet for stored, repeatedly read datasets
- CSV or JSON for exchange with other systems
- Chunked reads or DuckDB/Polars for files larger than memory
When to avoid or be careful
- Re-parsing huge CSVs in every notebook
- Letting pandas guess types for IDs and dates
- Using Excel as an automated data source
File formats compared
Strengths: Universal, human-readable.
Watch out: Slow, large, no types; encoding and delimiter issues.
Strengths: Flexible structure.
Watch out: Verbose; needs flattening for analysis.
Strengths: Small, fast, typed, columnar, filterable.
Watch out: Binary; not for manual editing.
Strengths: Familiar to stakeholders.
Watch out: Row limits, hidden formatting, error-prone as a data source.
Interview signals & numbers to know
When this topic comes up
- “Loading the CSV takes minutes”
- “UnicodeDecodeError when reading a file”
- “Flatten this nested JSON”
- Parquet vs CSV
- Out-of-memory reads
Benchmarks & rules of thumb
- ≈ 5–10×
- typical Parquet size reduction vs CSV
- 48 s → 2 s
- load time in the example
- 500,000
- a common chunksize
Common mistakes & follow-ups
Common interview mistakes
- Reading ID columns without
dtype, so leading zeros vanish and big integers become floats. - Ignoring
UnicodeDecodeErrorby switching to errors="ignore" and silently dropping characters. - Writing to Parquet with the index included by accident and later needing to drop it.
Likely interviewer follow-ups
- Why is Parquet faster than CSV?
- How would you load a file bigger than memory?
- How do you turn a list of nested orders into a flat table?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Working with CSV, JSON, Parquet & Excel with data science interview Q&A and hands-on practice.