So I was trying to replace np.nan
values in my dataframe with None
and noticed that in the process the datatype of the float
columns in the dataframe changed to object
even when they don't contain any missing data.
As an example:
import pandas as pd
import numpy as np
data = pd.DataFrame({'A':np.nan,'B':1.096, 'C':1}, index=[0])
data.replace(to_replace={np.nan:None}, inplace=True)
Call to data.dtypes
before and after the call to replace
shows that the datatype of column B changed from float to object whereas that of C stayed at int.
If I remove column A from the original data that does not happen.
I was wondering why that changes and how I can avoid this effect.