繁体   English   中英

Python:替换数据框中的字母数字值

[英]Python: Replacing alphanumeric values in Dataframe

我尝试删除而不去除实际单词的单词开头有\\ t和\\ r单词。

例如, "\\tWant to go to the mall.\\rTo eat something."

我已经从SO尝试了三天的一些事情。 它是Pandas Dataframe,所以我认为这个答案是最好的:

Pandas DataFrame:从列中的字符串中删除不需要的部分

但是以此为我自己的解决方案制定公式是行不通的。

i = df['Column'].replace(regex=False,inplace=False,to_replace='\t',value='')

我不想使用正则表达式,因为很难表达该表达式,因为我试图去掉'\\ t',如果可能也去掉'\\ r'。

这是我的正则表达式: https : //regex101.com/r/92CUV5/5

尝试以下代码:

def remove_chars(text):
    return str(re.sub(r'[\t\r]','',text))

i = df['Column'].map(remove_chars)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM