8

I am trying to subset a pandas dataframe based on values of two columns. I tried this code: df[df['gold']>0, df['silver']>0, df['bronze']>0] but this didn't work.

I also tried: df[(df['gold']>0 and df['silver']>0). This didn't work too. I got an error saying:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

What would you suggest?

1

1 Answer 1

16

I will answer my own question, hoping it will help someone. I tried this and it worked. df[(df['gold']>0) & (df['silver']>0)]

Note that I have used & instead of and and I have used brackets to separate the different conditions.

Sign up to request clarification or add additional context in comments.

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.