Pandas - Different Dtype Column Before/after Reading A File
I'm referring to this question since I'm facing with a weird behaviour of column types before and after reading the same dataframe from a .csv. Starting from: In [137]: df Out[137]
Solution 1:
You might want to use pickle IO:
import pandas as pd
df = pd.DataFrame({'a': [['a', 'b']]})
df.a.dtype
df.to_pickle('stuff.pkl.bin')
>>> pd.read_pickle('stuff.pkl.bin').a
0 [a, b]
Name: a, dtype: object
CSV is a very limited, textual, format. Conversely, pickle
(and its variants) are binary object formats.
Post a Comment for "Pandas - Different Dtype Column Before/after Reading A File"