0

Looking to see if someone know how to chain multiple conditions in pandas.... I am looking form something like this:

df[(df.col1>2)&df.col2<5) or (df.col5==5)&(df.col3>=78)]

so far I have found no solution that allows me to include an or condition like in my example.

Any help os appreciated1

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • 5
    What's wrong with `|` ? `df[((df.col1 > 2) & (df.col2 < 5)) | ((df.col5 == 5) & (df.col3 >= 78))]` Near identical example provided in [Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()](https://stackoverflow.com/q/36921951/15497888) – Henry Ecker Sep 07 '21 at 19:08

1 Answers1

0

same as and have a character so dose or use the | for or statement and sometimes pandas like more ()

df[((df.col1>2)&df.col2<5)) | ((df.col5==5)&(df.col3>=78))]
gal peled
  • 467
  • 5
  • 8