Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 2.7 熊猫搜索字符串包含\&引用;_Python 2.7_Pandas - Fatal编程技术网

Python 2.7 熊猫搜索字符串包含\&引用;

Python 2.7 熊猫搜索字符串包含\&引用;,python-2.7,pandas,Python 2.7,Pandas,我有一个python系列,我希望搜索包含“\”的特定字符串格式 目前我正在使用 pd.str.contains("text1\text2").any() 但是,这不起作用,因为\是保留字符 我非常感谢有关此的任何输入使用参数regex=False,在pandas中最好不要使用变量pd,因为要将pandas加载到您的命名空间中,需要使用: import pandas as pd s.str.contains("text1\text2", regex=False).any() 或通过\转义:

我有一个python系列,我希望搜索包含“\”的特定字符串格式

目前我正在使用

 pd.str.contains("text1\text2").any()
但是,这不起作用,因为\是保留字符


我非常感谢有关此的任何输入

使用参数
regex=False
,在pandas中最好不要使用变量
pd
,因为要将pandas加载到您的命名空间中,需要使用:

import pandas as pd

s.str.contains("text1\text2", regex=False).any()
或通过
\
转义:

s.str.contains("text1\\text2").any()
样本:

s = pd.Series(['text1\text2','text1\text2\dd','text1'])
print (s)
0       text1\text2
1    text1\text2\dd
2             text1
dtype: object

print (s.str.contains("text1\text2", regex=False))
0     True
1     True
2    False
dtype: bool

print (s.str.contains("text1\\text2"))
0     True
1     True
2    False
dtype: bool

谢谢,这太完美了,尽管选项2不起作用。我已经试过了,但你的选择1是完美的。