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.
dtype; the behavior in OP does not appear ifAis dropped prior to the replacement.NaNsshould also affect float columns with no missing values. I'd suggest reporting it as @ignoring_gravity suggests if you cannot find related issuesnp.nanvalue exists, as in there is no clear definition ofNonein a string column or a numeric column, thus its treated as an object by default.