Pandas/Performance & scale 8 min

Dtypes and memory

Make a frame several times smaller without losing data.

dtypecategorymemory

memory_usage(deep=True) shows where the bytes go. Object (string) columns are usually the worst offenders.

python · editable
loading editor…

Converting a repeated-value text column to 'category' stores each distinct value once, and downcasting numbers to the narrowest type that fits does the rest.

python · editable
loading editor…

Try it: Convert the product column to category as well and re-measure.

When a file is too big to load, read it in chunks with pd.read_csv(..., chunksize=...), aggregate each chunk, then combine the small results.