0

I want to see if I have some values from a list in multiple columns from my pandas dataframe.

Basically, I want to look over my column A, B and C if the values from a list exists and if so filter the rows where those values exist. For that I am using this:

processes = ['process_A', 'process_B']
df[df.col_A.isin(processes),df.col_B.isin(processes), df.col_C.isin(processes)].any()

And already try this:

df[df.col_A.isin(processes) OR df.col_B.isin(processes) or df.col_C.isin(processes)]

But I got a lot of errors or unexpectables results.

2 Answers 2

2

.isin returns a boolean Series, you need to use | for logical OR between the values.

try this:

df[df.col_A.isin(processes) | df.col_B.isin(processes) | df.col_C.isin(processes)]
Sign up to request clarification or add additional context in comments.

Comments

0

Using any as below

df[df[['col_A','col_B','col_C']].isin(processes).any(1)]

Comments

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.