Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

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.

The shortcut

Match the file to its one question: Excel → sheet, JSON → shape, Parquet → columns. Then run the usual check: shape, head(), dtypes.

Loading the finance workbookStep 1 of 4
  1. Name the question

    It is Excel, so: which sheet? The workbook has sheets January, February, March.

The trap is reading only the first sheet without noticing. The code runs, the numbers look plausible, and eleven months are missing. Check the sheet names before trusting a total.

Drills

Answer fast — trust the rule.

quick drill

What does pd.read_excel("book.xlsx") load when the file has four sheets?

quick drill

What columns does pd.json_normalize([{"id": 7, "shop": {"city": "Delhi"}}]) produce?

quick drill

Which is a real advantage of Parquet over CSV for analysis?

quick drill

What type does pd.read_excel("book.xlsx", sheet_name=None) return?

Remember

  • Every format has a read_ and a to_; learn the one question each asks.
  • Excel → which sheet; JSON → what shape; Parquet → which columns.
  • Default Excel reads the first sheet only: check sheet names before trusting totals.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainThree files, three questions

You receive a workbook with twelve monthly sheets, a nested JSON export and a large Parquet file. Explain how you would load each correctly into pandas.