For example;
pd.Series('ASKING CD.').str.contains('AS')
Out[58]:
0 True
dtype: bool
pd.Series('ASKING CD.').str.contains('ASG')
Out[59]:
0 False
dtype: bool
pd.Series('ASKING CD.').str.contains('SK.')
Out[60]:
0 True
dtype: bool
Why the 3rd output is True? There is no 'SK.' sequence in passed string. 'dot' character doesn't mean anything?
Regex .
means match any character. Solutions is escape .
or add parameter regex=False
:
print(pd.Series('ASKING CD.').str.contains(r'SK\.'))
0 False
dtype: bool
print(pd.Series('ASKING CD.').str.contains('SK.', regex=False))
0 False
dtype: bool
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