Skip to the workspace
Pebellslearn by building
Loading Data  ›  Lesson

Excel, JSON and Parquet

Excel 14 minEach file format has a read and a to function in pandas, and each asks one key question: which Excel sheet, what JSON shape, which Parquet columns.

python data analysis / Excel, JSON and Parquet

Explore each scene at your own pace.

01 · The rule

The rule

Excel, JSON and Parquet

The finance team sends a spreadsheet with one sheet per month. The website's order system hands you JSON. The data team stores last year's history as Parquet. Three formats, one habit: each has a pd.read_… function, and each has one thing you must tell it.

The rule

Every format has a read_ and a to_; learn the one question each asks.

Excel (.xlsx): the question is which sheet?

march = pd.read_excel("sales_2024.xlsx", sheet_name="March")
every = pd.read_excel("sales_2024.xlsx", sheet_name=None)   # dict of all sheets

With no sheet_name, you get only the first sheet. With None, you get a dictionary: sheet name to DataFrame. Reading Excel needs an extra package, usually openpyxl.

JSON: the question is what shape is it? Flat records map straight onto rows:

# [{"branch": "Pune", "copies": 3}, {"branch": "Delhi", "copies": 5}]
orders = pd.read_json("orders.json")

Nested JSON, where a value is itself an object, needs flattening:

records = [{"id": 1, "shop": {"city": "Pune", "floor": 2}}]
pd.json_normalize(records)
# columns: id, shop.city, shop.floor

json_normalize turns each nested key into a column joined with a dot.

Parquet: the question is which columns do I need? Parquet is a compressed, column-by-column binary format built for analysis. It keeps each column's dtype, so dates stay dates and integers stay integers with no guessing.

history = pd.read_parquet("sales_2023.parquet", columns=["branch", "copies"])
sales.to_parquet("sales.parquet")

Because it is stored column by column, loading two columns out of fifty reads only those two, which is much faster than CSV.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.