Python pandas str.contains()给出了错误的结果?
比如,Python pandas str.contains()给出了错误的结果?,python,string,pandas,Python,String,Pandas,比如, 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 为什么第三个输出为真?传递的字
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
为什么第三个输出为真?传递的字符串中没有“SK.”序列“点”字符没有任何意义?Regex
表示匹配任何字符。解决方案是escape
或add参数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
谢谢我一开始确实试过“SK\”,但没想到。现在我注意到默认参数是**regex=True**。现在可以了。谢谢。