0

I have a working code that I am trying to reduce

df['Criteria'] = (df['Alpha'] == 3) | (df['Alpha'] == 4) 

I tried with error the below (TypeError: isin() takes 2 positional arguments but 3 were given)

df['Criteria'] = df['Alpha'].isin(3,4)

I took reference from Pythonic Way to have multiple Or's when conditioning in a dataframe

Can anyone advise me on this please? Thank you

jpp
  • 147,904
  • 31
  • 244
  • 302
J Ng
  • 617
  • 7
  • 17

1 Answers1

2

You are close, need list,tuple, array or set in isin:

Series.isin(values)

values : set or list-like

The sequence of values to test. Passing in a single string will raise a TypeError. Instead, turn a single string into a list of one element.

df['Criteria2'] = df['Alpha'].isin([3,4])
Community
  • 1
  • 1
jezrael
  • 729,927
  • 78
  • 1,141
  • 1,090