0

I am trying to do something like

exclude_values = range(low, high)  # for the sake of example
df = df[df['blah'] not in exclude_values]

which just raises the "truth value of a Series is ambiguous" exception. The problem is, I can't see how to change this syntax so as not to use not in. What (presumably very obvious) thing am I missing?

Gavin Kirby
  • 43
  • 10

2 Answers2

1

Use isin

df[~df['blah'].isin(exclude_values)]
rafaelc
  • 57,686
  • 15
  • 58
  • 82
Danny
  • 470
  • 4
  • 14
0

Use idiomatic pandas methods and bitwise logic:

df = df[~round(df.blah).isin(exclude_values)]
rafaelc
  • 57,686
  • 15
  • 58
  • 82
Gavin Kirby
  • 43
  • 10