Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pandas str.contains()给出了错误的结果?_Python_String_Pandas - Fatal编程技术网

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**。现在可以了。谢谢。