1

I want to remove the rows where Área is below 10 and above 1000.

So this works perfectly:

x = dataset[(dataset['Área'] > 10) ]

But this doesn't:

x = dataset[(dataset['Área'] > 10) and (dataset['Área'] < 1000)]

Please explain. I'm following this tutorial here.

Thank you.

unstuck
  • 563
  • 2
  • 12
  • 29
  • 2
    `x = dataset[(dataset['Área'] > 10) & (dataset['Área'] < 1000)]` – Henry Ecker Jul 23 '21 at 14:28
  • 2
    Use `&` instead of `and` – not_speshal Jul 23 '21 at 14:29
  • ['and' (boolean) vs '&' (bitwise) - Why difference in behavior with lists vs numpy arrays?](https://stackoverflow.com/q/22646463/15497888), [difference between “&” and “and” in pandas](https://stackoverflow.com/q/54315627/15497888), [Logical operators for boolean indexing in Pandas](https://stackoverflow.com/q/21415661/15497888) – Henry Ecker Jul 23 '21 at 14:29
  • Maybe use the "&" symbol instead of "and". – jimmie_roggers Jul 23 '21 at 14:30

1 Answers1

4

That it because and is logical and, ie. True and False will yield False. You need bitwise-and, ie. &.

Try:

x = dataset[(dataset['Área'] > 10) & (dataset['Área'] < 1000)]
Vinzent
  • 1,070
  • 1
  • 9
  • 14