Sphere
Log in Join
☆ 5

pandas read_csv eats all RAM on a 2 GB file

Trying to read a 2 GB CSV with pandas. The process uses over 8 GB and gets killed. I only need 6 of 40 columns and want to filter by date.

⚑ Report

3 replies

☆ 0
D Dan H. ·2026-10-01#1

Pass usecols for the 6 columns and specify dtype explicitly, especially for strings that pandas would otherwise infer as object.

⚑ Report
☆ 0
Z Zoe ·2026-10-01#2

That helped but still uses about 4 GB. I do not need the whole file in memory at once.

⚑ Report
☆ 0
H Hana ·2026-10-01#3

Use chunksize=100000 and process chunk by chunk, or convert the file to Parquet once with DuckDB and query that. Parquet plus predicate pushdown is usually the bigger win.

⚑ Report
Log in to reply.