Skipper Lin
Skipper Lin

Reputation: 179

How to filter the pandas dataframe when one cell value of all columns equals to a specific string

I have a dataframe with around 20-30 columns. I would like to filter for all the rows when one cell value in that rows equals to "Fail".

The dataframe would look like this:

    Column_1 Column_2 ... Column_30
0      Pass   Pass          Fail
1      Pass   Pass          Pass
2      Fail   Pass          Pass
3      Pass   Pass          Pass
4      Pass   Pass          Pass
..

I would like to have row 0 and 2 filter out. Is there any way to achieve that? Thank you so much.

Upvotes: 2

Views: 283

Answers (1)

BENY
BENY

Reputation: 323246

Try with any

out = df[~df.eq('Fail').any(1)]

Upvotes: 5

Related Questions