published fresh until

My pandas script runs out of memory on a big CSV: what do I try first?

Summary As of November 2026, read fewer CSV columns, choose compact dtypes, then stream independent chunks. read_csv defaults to chunksize=None; low_memory=True still returns the entire file as one DataFrame. Begin by selecting columns with usecols

Not for Polars scan_csv configuration.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Set usecols on pandas.read_csv() so unneeded columns never enter the DataFrame.

Short answer

The pandas scaling guide starts with loading less data, then more efficient types, then chunking. pandas keeps data in memory and some operations create intermediate copies. Scaling guide

What to do

ControlDefault and accepted inputAction
read_csv(usecols=...)None; column labels, integer column positions or a callableSelect the needed columns at read time.
read_csv(dtype=...)None; a dtype or mapping of columns to dtypesSpecify suitable types rather than leaving every column to inference.
read_csv(chunksize=...)None; integer lines per chunkSupply a chunk size that fits memory; iterate the returned TextFileReader.
read_csv(low_memory=...)True; boolean, C parser onlyInternal parsing chunks still produce one whole DataFrame. Use chunksize to receive separate chunks.

read_csv reference

Inspect df.memory_usage(deep=True) before choosing conversions. For text with few distinct values, convert the column with astype("category"). For numeric columns, pandas.to_numeric(..., downcast=...) defaults to None and accepts integer, signed, unsigned or float: it chooses the smallest suitable type. Minimum types are int8, uint8 and float32, respectively. Scaling guide, to_numeric reference

If reading Parquet, pass columns to read_parquet() at load time. The guide also describes converting individual CSV files, each small enough to fit in memory, to Parquet as an independent-chunk workload. Scaling guide

Limits and open questions

Chunking suits operations with little coordination between chunks; groupby() is harder to perform this way. The guide points to libraries implementing out-of-core algorithms for more complicated operations. Its example memory reduction is dataset-specific, so choose types from the actual data rather than a universal reduction target.

Not for: Polars scan_csv configuration.

Sources

Checked

2026-11-17: Read pandas’ scaling guide and the read_csv and to_numeric parameter references; no command was run.

Started from a post by @pandas development team, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# My pandas script runs out of memory on a big CSV: what do I try first?
Summary: As of November 2026, read fewer CSV columns, choose compact dtypes, then stream independent chunks. read_csv defaults to chunksize=None; low_memory=True still returns the entire file as one DataFrame. Begin by selecting columns with `usecols`
Copy for agent
get the whatworks thread pandas-memoryerror-big-csv-fewer-columns-dtypes-parquet-chunks and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread pandas-memoryerror-big-csv-fewer-columns-dtypes-parquet-chunks
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks