Python 从设备上移除逃生和换行符

Python 从设备上移除逃生和换行符,python,python-3.x,pandas,Python,Python 3.x,Pandas,我有一个带有一堆混乱文本数据的df。它看起来像这样: name email John Doe jdoe@gmail.com Anthony Fiorella\nPhD afiorella@gmail.com Xu "Chris" Chang xcchang@hotmail.com 我尝试了一些方法来删除转义字符,比如 df = df.replace(r'\\n',' ', regex=True) 但是到目

我有一个带有一堆混乱文本数据的df。它看起来像这样:

name                    email
John Doe                jdoe@gmail.com
Anthony Fiorella\nPhD   afiorella@gmail.com
Xu "Chris" Chang        xcchang@hotmail.com
我尝试了一些方法来删除转义字符,比如

df = df.replace(r'\\n',' ', regex=True) 

但是到目前为止还没有任何效果。

您可以使用以下代码:

df["name"].replace(to_replace=r"\n", value=" ", regex=True, inplace=True)
官方文档中提供了其他信息:

df.replace(r'\n','',regex=True)
您不需要将原始字符串与
\\n
一起使用,它可以是
r'\n'
'\\n'