Yes good point, for a python list (and probably other data types too). You’re not wrong. Doesn’t work well for a Pandas series though. But, as usual, there are other options. See for example this then:

data = {'var1':[1,2,3,4,5],
'var2':'This here is five words'.split()}
df = pd.DataFrame(data)
# Try in... (returns False)
'here' in df['var2']
# Try in... with to_list() method (returns True)
'here' in df['var2'].to_list()
# And, I'd also point folks to .isn().max().sum()
# which is probably also functionally equivalent.
# Returns True
df['var2'].isin(['This', 'now']).max()
# Returns One (1)
df['var2'].isin(['This', 'now']).max().sum()

Thanks for the comment and suggestion.

--

--

--

Ask about my free career course. I mentor new (💫) and aspiring data scientists enter (🚪) and level up (📈) in the field.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adam Ross Nelson

Adam Ross Nelson

Ask about my free career course. I mentor new (💫) and aspiring data scientists enter (🚪) and level up (📈) in the field.

More from Medium

Simulate the 2022 NCAA Men’s Basketball Tournament

In Operator and Having Clause in SQL Python

Chi-Square Test in Python: Analyzing Enabling Factors of Mental Health at Work

R Programming for data science and machine learning