Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.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从带空格的字符串开始_Python_Replace - Fatal编程技术网

替换“\\&引用;使用Python从带空格的字符串开始

替换“\\&引用;使用Python从带空格的字符串开始,python,replace,Python,Replace,dataframe由df[“Notes”]列组成,该列包含每个观察的文本。以下是几个观察的片段: 'Storm Data (Vol. 11, No. 8) reports associated with Hurricane Camille (August 1969) indicate \\... substantiated amounts up to 31 inches ... falling mainly in Nelson and adjacent counties ....\\&qu

dataframe由df[“Notes”]列组成,该列包含每个观察的文本。以下是几个观察的片段:

   'Storm Data (Vol. 11, No. 8) reports associated with Hurricane Camille (August 1969) indicate \\... substantiated amounts up to 31 inches ... falling mainly in Nelson and adjacent counties ....\\" The 14.28 inches at Williamsburg fell in conjunction with Hurricane Floyd."',

   'These were values of 89.90\\ at Montebello Fish Hatchery and 87.33\\" at Roanoke 5.8 SW (CoCoRaHS). These were determined not to be valid statewide precipitation records. A separate report detailing these values is available here."',
我试图使用以下代码将文本中的“\”替换为空格(“”):

df[“Notes”]=df[“Notes”]。替换(“\\”,“”)


代码没有给出任何错误,但我无法将“\”替换为“”。列的数据类型为“O”。

如果要将字符串函数应用于pandas系列,则需要将
.str
应用于列,然后
.replace

df[“Notes”]=df[“Notes”].str.replace(“\\”,“”)
本质上,
.str
方法允许panda在列中的字符串对象上迭代,并在每个元素上运行
str.replace(“\\”,“”)