pandas DataFrames that contain columns of mixed data types are stored in a more general format (such as object), resulting in inefficient memory usage and slower computation times.
df.infer_objects()
infers the true data types of columns in a DataFrame, which helps optimize memory usage in your code.
In the code above, df.infer_objects()
converts the data type of “col1” from object to int64, saving approximately 27 MB of memory.