pandas for analysis · mid
Big files and clear charts in pandas
When a file does not fit in memory, read less, read in chunks or use another engine. A leadership chart needs complete weeks, a few series, labelled units and a finding in the title.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- In memory, text becomes objects and numbers 8 bytes each. Two to five times the file size is normal.
- Read less: usecols for the needed columns, dtype for each (category for city, float32 for amount), and parse only the date column. engine="pyarrow" is faster.
- Chunks: read_csv(..., chunksize=2_000_000), aggregate each chunk by date and city, then add the small results.
- DuckDB runs SQL straight on a CSV without loading it all. Polars scan_csv is lazy. Convert once to Parquet (columnar, compressed, typed) for fast later reads.
- Long term, the data belongs in the warehouse and the report runs there. Buying more RAM is not the first answer.
- Weekly chart: keep the last 12 complete weeks and drop the current partial week, which would look like a crash.
- Top five cities: df.groupby("city")["amount"].sum().nlargest(5).index. Weekly totals: groupby([pd.Grouper(key="order_date", freq="W-SUN"), "city"]).sum().unstack(). W-SUN weeks run Monday to Sunday.
- Label units (rupees lakh or crore), add a legend, and put the finding in the title (Pune overtook Hyderabad in October), not 'Weekly GMV by city'. Mark known events such as a sale week. Check plotted numbers against the source total.
The red pen
Common traps: mistake → fix
Mistake: Read everything as text and fix types later
Fix: it uses much more memory.
Mistake: Plot all 400 cities
Fix: show the few that matter.
Mistake: The current week is fine in a trend
Fix: a partial week looks like a drop.
Easy to hard
Questions interviewers ask, easy to hard
- A 12 GB CSV crashes pandas on a 16 GB laptop. What do you do?
- Why convert a CSV to Parquet?
- Write pandas code for weekly GMV for the top five cities.
- What makes a chart ready for a leadership deck?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.