I have some memory inconsistencies when I am using a Pandas DataFrame.
Here is my code skeleton:
import pandas as pd
import numpy as np
columns_dtype = {'A': np.int16, 'B': np.int8, ...}
df = pd.read_csv('my_file.csv', dtype=columns_dtype)
That is basically just reading a csv file with pandas while controlling column data types. But then, when I am looking for how much memory is allocated to my program, the information does not seem coherent.
Info 1:
df.info(memory_usage='deep')
That gives : memory usage: 482.6 MB
Info 2:
import dill, sys
sys.getsizeof(dill.dumps(df))
That gives : 506049782 (so 506 Mb)
Info 3:
The RAM allocated to my program is : 1.1 GiB (or 1.2 Gb)
Additional info (but i do not think it is relevant):
the size of my_file.csv is 888 Mb (ls -lh)
The issue:
As I am just loading my csv file into a Pandas DataFrame object, why does my program needs more than 1 Gb of RAM whereas the object size is about 0.5 Gb ?
Many thanks