You can use the vectorised str.contains
to test if a string is present/contained in each row :
In [262]:
testData['value'].str.contains(testData['value'][0])
Out[262]:
0 True
1 False
2 False
Name: value, dtype: bool
If you're after whether it's present in any row then use any
:
In [264]:
testData['value'].str.contains(testData['value'][0]).any()
Out[264]:
True
OK to address your last question:
In [270]:
testData['value'][0] in testData['value']
Out[270]:
False
This is because pd.Series.__contains__
is implemented:
def __contains__(self, key):
"""True if the key is in the info axis"""
return key in self._info_axis
If we look at what _info_axis
actually is:
In [269]:
testData['value']._info_axis
Out[269]:
RangeIndex(start=0, stop=3, step=1)
Then we can see when we do 'abc'
in testData['value']
we're really testing whether 'abc'
is actually in the index which is why it returns False
Example:
In [271]:
testData=pd.DataFrame({'value':['abc','cde','fgh']}, index=[0, 'turkey',2])
testData
Out[271]:
value
0 abc
turkey cde
2 fgh
In [272]:
'turkey' in testData['value']
Out[272]:
True
We can see that is returns True
now because we're testing if 'turkey' is present in the index