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:

import pandas as pddata = {'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.