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!

user3451026
  • 61
  • 1
  • 7
  • see explanation [here](http://stackoverflow.com/questions/21415661/logic-operator-for-boolean-indexing-in-pandas?rq=1) – bunji Nov 21 '16 at 17:58

2 Answers2

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

Mohamed AL ANI
  • 2,012
  • 1
  • 12
  • 29
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))]
burhan
  • 924
  • 4
  • 11