I have a pandas series of
dtype: object that contains both numbers and characters. When I wanted to check if a certain value exists in that series I got confused by the way how the existence of a certain value is checked.
For the example below, I would intuitively expect, that
'a' is in the series and also
'1'. Furthermore, I wouldn’t expect that the (integer) value
1 exists in the series, because AFAIK the
dtype: object in pandas can be (roughly?) compared with python’s string type.
Does anyone has an an explanation for this behavior?
s = pd.Series(('a',1,2)) if 'a' in s: print('a is in s') else: print('a is not in s') if '1' in s: print('string 1 is in s') else: print('string 1 is not in s') if 1 in s: print('integer 1 is in s') else: print('integer 1 is not in s')
a is not in s string 1 is not in s integer 1 is in s