How do you handle large datasets that do not fit into memory with Pandas?

Quick Overview

Explain how to work with a dataset larger than memory using pandas and the tools around it. Tests loading only the data you need, chunked processing and how per-chunk results combine, columnar formats, and when to move the work to an out-of-core engine or a database.

How do you handle large datasets that do not fit into memory with Pandas?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

How do you handle large datasets that do not fit into memory with Pandas? ```hint Measure what you need Before picking a tool, ask how much of the file the analysis actually needs: which columns, which rows, and at what precision. ``` ```hint Combining pieces If you process the data in pieces, check which statistics can be rebuilt exactly from per-piece results and which cannot. ``` ### What a Strong Answer Covers - Reduces what is loaded first (columns, rows, dtypes, file format) and shows how to measure memory use. - Explains chunked processing and how per-chunk results are combined correctly. - Identifies operations that do not split cleanly over chunks, such as exact medians, distinct counts, sorts and large joins, and how to handle them. - Names out-of-core and database options and says when each one fits better than plain pandas. - Shows working code for at least one approach. ### Follow-up Questions - How would you compute the exact median of a column in a 200 GB CSV? - You need to join a 100 GB events file to a 50 MB users table. How would you do it with pandas? - When would you move the work to Spark or a warehouse instead of DuckDB, Polars or Dask on one machine? - How do you check that a dtype downcast did not lose information?

Overview: Explain how to work with a dataset larger than memory using pandas and the tools around it. Tests loading only the data you need, chunked processing and how per-chunk results combine, columnar formats, and when to move the work to an out-of-core engine or a database.

General logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

How do you handle large datasets that do not fit into memory with Pandas?

What a Strong Answer Covers Guidance

  • Reduces what is loaded first (columns, rows, dtypes, file format) and shows how to measure memory use.
  • Explains chunked processing and how per-chunk results are combined correctly.
  • Identifies operations that do not split cleanly over chunks, such as exact medians, distinct counts, sorts and large joins, and how to handle them.
  • Names out-of-core and database options and says when each one fits better than plain pandas.
  • Shows working code for at least one approach.

Follow-up Questions Guidance

  • How would you compute the exact median of a column in a 200 GB CSV?
  • You need to join a 100 GB events file to a 50 MB users table. How would you do it with pandas?
  • When would you move the work to Spark or a warehouse instead of DuckDB, Polars or Dask on one machine?
  • How do you check that a dtype downcast did not lose information?