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 ato_; 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 sheetsWith 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.floorjson_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.