I want to replace all 0
s and 1
s by True
and False
. I tried the below code but the data frame doesn't change.
import pandas as pd
d = {'A': [1, 1, 0, 1, 0, 1, 0],
'B': [0, 0, 0, 0, 0, 1, 1]
}
df = pd.DataFrame(data=d)
print(df)
print(df.dtypes)
print(df.replace(1, True).replace(0, False))
print(df.dtypes)
Console output:
A B
0 1 0
1 1 0
2 0 0
3 1 0
4 0 0
5 1 1
6 0 1
A int64
B int64
dtype: object
A B
0 1 0
1 1 0
2 0 0
3 1 0
4 0 0
5 1 1
6 0 1
A int64
B int64
dtype: object