I am trying to check if a value exists in a pandas series, However, I found an interesting fact:
s1 = pd.Series(['one', 'one1', '1', ''])
'one' in s1
False
'one' in set(s1)
True
Why wouldn't the in
operation work for the Series object? Thanks!
in
checks if index is in this series
In[29]: s1.__contains__
Out[29]:
<bound method NDFrame.__contains__ of
0 one
1 one1
2 1
3
dtype: object>
In[30]: 'one' in s1
Out[30]: False
In[31]: 0 in s1
Out[31]: True
In[32]: 1 in s1
Out[32]: True
In[33]: 2 in s1
Out[33]: True
In[34]: 3 in s1
Out[34]: True
In[35]: 4 in s1
Out[35]: False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With