pandas interview question
A pandas script runs out of memory or takes too long on a large file. How do you fix it?
Scenario Asked in Machine Learning Engineer · Data Engineer interviews
Summary
Load less and store it more compactly: read only needed columns (usecols), set efficient dtypes (categories for
repeated strings, smaller numeric types), process in chunks or with filters, use vectorised operations instead of
apply/loops, and switch to Parquet. If it still doesn't fit, use Polars, DuckDB or a distributed engine.
Keep reading with a membership
The full answer with examples, key points and comparisons is part of the membership, along with every other interview answer, progress tracking and Daily Review. Most-asked answers stay free to read.
More pandas questions
- What is the difference between loc and iloc in pandas, and what is the SettingWithCopyWarning?
- How do you handle missing data in pandas?
- Explain groupby in pandas: split-apply-combine, agg, transform and filter.
- Write pandas code that finds each customer's latest order and their 30-day rolling spend.
- When would you use merge, join or concat in pandas?