Reputation: 499
I have a column in a dataframe that I need to convert from object to boolean. However, the value changes from False
to True
when using astype
. Any ideas on how to prevent this?
df['isgood']
returns:
0 True
1 False
2 False
df['isgood'].astype(bool)
returns:
0 True
1 True
2 True
Upvotes: 5
Views: 19259
Reputation: 323226
The True and False in your df type is str, if you need convert it to bool type
df.isgood=='True'
Out[420]:
0 True
1 False
2 False
Name: isgood, dtype: bool
Upvotes: 10