'Filter the non-blank row in a DataFrame with Pandas
I have a 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. 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. What did I miss?
Solution 1:[1]
If you set isnull() to == False it will work:
df2022new = df2022[(df2022['name'] != 'Mike') & (df2022['comment'].isnull() == False)]
# name comment product
#2 Nite bad 2234
#4 Tim bad 3432
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rawson |
