Finding a string in pandas.Series using the IN operator
Any idea why I can't directly use the in operator to find a string in a Series?
Think of a Series more like an ordered dictionary than a list-- membership testing in a Series is of the index (like keys in a dictionary), not of the values. You could access the values via under the .values
attribute:
>>> s = pd.Series([1,3,5,True,6,8,'findme', False])
>>> 7 in s
True
>>> 7 in s.values
False
>>> 'findme' in s
False
>>> 'findme' in s.values
True