← All Python interview questions

Shrink a DataFrame's memory footprint

MediumPandas — CleaningAmazonWalmart

A 40-million-row extract will not fit in memory with default dtypes.

Write optimise(df) that returns a copy where integer columns are downcast to the smallest safe integer type, float columns to the smallest safe float type, and object columns with fewer than 50% unique values become category.