2

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.

1 Answer 1

5

Try with any

out = df[~df.eq('Fail').any(1)]
Sign up to request clarification or add additional context in comments.

4 Comments

thank you so much for the amazing solution using any. Just one quick follow-up question: is there anyway we could grab the column names whenever there is a Fail in that record?
@SkipperLin you want to have by row ?
yes technically. In my original dataset, I would love to obtain the column names that contain a Fail in a list format (i.e., [Column 1, Column 30])
@SkipperLin s = df.eq('Fail').any() ; s[s].index

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.