I have a dataframe that contains one hot encoded columns of 0s and 1s which is of dtype int32
.
a b h1 h2 h3
xy za 0 0 1
ab cd 1 0 0
pq rs 0 1 0
I want to convert the columns h1,h2 and h3 to boolean so here is what I did..
df[df.columns[2:]].astype(bool)
But this changed all values of h1-h3 as TRUE
.
I also tried
df[df.columns[2:]].map({0:False, 1:True})
but that does not work either. (AttributeError: 'DataFrame' object has no attribute 'map')
What is the best way to convert specific columns of the dataframe from int32
0s and 1s to boolean (True
/False
)?