简体   繁体   English

用Pandas过滤DataFrame中的非空行

[英]Filter the non-blank row in a DataFrame with Pandas

I have a DataFrame df2022 :我有一个 DataFrame df2022

name    comment    product
Mike     good       2432
Tim                 1231   
Nite     bad        2234
Mike                3433 
Tim      bad        3432

I want to filter the rows with the name that is not Mike and the comment that is not blank .我想过滤名称不是 Mike 且评论不是空白的行。 I did the following:我做了以下事情:

df2022new = df2022[(df2022['name'] != 'Mike') & df2022['comment'].isnull()] 

However, it doesn't.然而,事实并非如此。 It only works with the first part, so I think the second select non-blank part is wrong.它只适用于第一部分,所以我认为第二个 select 非空白部分是错误的。 What did I miss?我错过了什么?

If you set isnull() to == False it will work:如果将isnull()设置为== False它将起作用:

df2022new = df2022[(df2022['name'] != 'Mike') & (df2022['comment'].isnull() == False)]
#   name comment  product
#2  Nite     bad     2234
#4   Tim     bad     3432

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

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