[英]Pandas not finding all values in column
When I try looking for all rows with a specific value in a column I don't get all the rows like when I filter for it in excel.当我尝试在列中查找具有特定值的所有行时,我并没有像在 excel 中过滤它时那样得到所有行。 Eg:
例如:
Column 1 is of type object and has rows of different numbers mixed with chars sometimes.第 1 列的类型为 object,有时会有不同数字的行与字符混合。
df[df['column1']== 250] returns 100 results
df[df['column1']=='250'] returns 50 results
What is causing this and how can I fix it?是什么原因造成的,我该如何解决?
I tried converting it again to object but no success.我尝试再次将其转换为 object 但没有成功。
Looks like some values in column1
are str
and some are int
.看起来
column1
中的一些值是str
,有些是int
。
Convert all values in one type, like this using Series.astype
:将所有值转换为一种类型,例如使用
Series.astype
:
df['column1'] = df['column1'].astype(str)
then do this:然后这样做:
df[df['column1']== '250']
You should get 150
records back now.你现在应该得到
150
条记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.