I discovered the hard way that Pandas in
operator, applied to Series
operates on indices and not on the actual data:
In [1]: import
It is may be helpful to think of the pandas.Series
as being a bit like a dictionary, where the index
values are equivalent to the keys
. Compare:
>>> d = {'a': 1}
>>> 1 in d
False
>>> 'a' in d
True
with:
>>> s = pandas.Series([1], index=['a'])
>>> 1 in s
False
>>> 'a' in s
True
However, note that iterating over the series iterates over the data
, not the index
, so list(s)
would give [1]
, not ['a']
.
Indeed, per the documentation, the index
values "must be unique and hashable", so I'd guess there's a hashtable under there somewhere.