Python 从对象到布尔值的转换总是使用astype返回True
我在数据框中有一列,需要将其从object转换为boolean。但是,使用Python 从对象到布尔值的转换总是使用astype返回True,python,pandas,Python,Pandas,我在数据框中有一列,需要将其从object转换为boolean。但是,使用astype时,该值会从False更改为True。有没有办法防止这种情况 df['isgood']返回: 0 True 1 False 2 False 0 True 1 True 2 True df['isgood'].astype(bool)返回: 0 True 1 False 2 False 0 True 1 True 2 True 如果需
astype
时,该值会从False
更改为True
。有没有办法防止这种情况
df['isgood']
返回:
0 True
1 False
2 False
0 True
1 True
2 True
df['isgood'].astype(bool)
返回:
0 True
1 False
2 False
0 True
1 True
2 True
如果需要将df类型转换为bool类型,那么df类型中的True和False是str
df.isgood=='True'
Out[420]:
0 True
1 False
2 False
Name: isgood, dtype: bool