df2 = pd.DataFrame({'test':[False,True,True]})
df2.loc[0,'Test']=np.nan
The above result df converting the 'test' column to floats, where the True's get converting into 1.0. Is it possible to set this value, keeping the dtype of the column to obj so I can mix float and bool's, i.e.
test
0 NaN
1 True
2 True
dtype=object
Yes. You need to tell Pandas that the column is of dtype
object
pd.DataFrame({'test':[False,True,True]}, dtype=object)
If altering an existing dataframe
df2['test'] = df2['test'].astype(object)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With