繁体   English   中英

熊猫显示False而不考虑逻辑运算

[英]Pandas shows False irrespective of the logical operation

wordtags.Count.head()
Out[44]: 
0    6
1    5
2    1
3    1
4    2
Name: Count, dtype: object

wordtags.Count==6
Out[45]: 
0        False
1        False
2        False
3        False
4        False
5        False
6        False
7        False
8        False

不管逻辑运算如何,Pandas都会显示False 第一行应为True

dtype: object表示Count是string( object )dtype,因此请尝试以下操作:

wordtags.Count=='6'

您可以将其转换为数字dtype:

wordtags['Count'] = pd.to_numeric(wordtags['Count'], errors='coerce')

如果有一列整数是字符串,建议将其转换为整数。

wordtags['Count'] = wordtags['Count'].astype(int)

现在,

wordtags.Count == 6
0     True
1    False
2    False
3    False
4    False
Name: Count, dtype: bool

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM