runtime

compare approaches one problem · two ways

Compare Approaches

The same problem solved different ways in Python, run on the same input, with what really differs and when to use each.

csv module vs pandas

Average order total per state, from the Online Store orders file.

what differs

csv gives every field as a string and leaves types to you. pandas infers column types, loads everything into memory, and provides vectorised operations.

at a glance

approachuse it when
A · csv.DictReaderNo dependencies, streaming large files row by row, or simple per-row logic.
B · pandasAnalysis: grouping, joining, reshaping, statistics on whole columns.

Watch out: pandas reads empty fields as NaN and may turn ID-like columns with leading zeros into numbers; pass dtype={"zip": str}.

the outputs

Each approach runs on the same input.

concepts

csv moduleDataFrametype inference

learn it

Read CSV rows as dictionaries · Series and DataFrames

related comparisons

Python loops vs pandas · csv.reader (indexes) vs csv.DictReader (names)

Uses the Online Store dataset.

A · csv.DictReader
B · pandas
Compare Python Approaches · Runtime