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
  • 159,742
  • 34
  • 281
  • 339
J Ng
  • 779
  • 7
  • 18

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
  • 822,522
  • 95
  • 1,334
  • 1,252