0

I'm looking to filter out any rows where two columns values are equal to 0 and 1. The following was my attempt at this but hasn't yielded any results.

x = x[x.value_1 != 0 and x.value_2 !=1]

Running this returns the following error:

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

I know it is possible to filter using either one of these two conditions alone. However, it doesn't seem to like when I use them together. Any advice on a quick fix that doesn't include merging? Thanks!

1
  • see explanation here Commented Nov 21, 2016 at 17:58

2 Answers 2

1

Just try it with parenthesis and & rather than and :

x = x[(x.value_1 != 0) & (x.value_2 !=1)]

I had the same issue

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

3 Comments

Note also the & rather than "and"
That is removing all instances of value_1 not equaling 0 and all instances where value_2 is not 1. I would like to remove only the instances where both value_1 is 0 and value_2 is 1.
I'm not sure but I believe you can't do that using this syntax. try using "pd.where" instead
0

Try this if you want anything except when value_1 is 0 and value_2 is 1:

x = x[~((x.value_1 == 0) & (x.value_2 == 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.