0

So I got a strange question...

I'm basically trying to do some filtering on a dataframe, and I realized these 2 lines result in a error.

sel = data[(data["Fare"] == 50) and (data["Sex"].isin(["male"]))]
sel = data[(data["Fare"] == 50) or (data["Sex"].isin(["male"]))]

But when I use | and &, instead of 'and' and 'or', it WORKS:

sel = data[(data["Fare"] == 50) & (data["Sex"].isin(["male"]))]
sel = data[(data["Fare"] == 50) | (data["Sex"].isin(["male"]))]

So my question is, why does the 'and' and 'or' not work?

Why do only the symbols work instead?

codingcow
  • 1
  • 1
  • because the operation must be vectorized and `and`/`or` do now allow it – mozway Jul 26 '22 at 09:10
  • 1
    does this post help you ? https://stackoverflow.com/questions/21415661/logical-operators-for-boolean-indexing-in-pandas –  Jul 26 '22 at 09:12

0 Answers0