I have a big data frame. I want to replace float 1.0 and 0.0 with true and false.
My code:
import pandas as pd
df = pd.DataFrame({"A":[1.0,0.0,1.0,0.0]})
df.replace(1.0,True,inplace=True).replace(0.0,False,inplace=True)
Present output:
AttributeError: 'NoneType' object has no attribute 'replace'
If I do it separately in two lines, it will work. I want to do it in one line.
Try with bool :-)
df.A=df.A.astype(bool)
df
Out[69]:
A
0 True
1 False
2 True
3 False
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