【发布时间】:2019-04-10 23:29:47
【问题描述】:
我正在尝试从数据框中删除所有标点符号,除了字符“”
我试过了:
def non_punct(df):
df['C'] = df['C'].str.replace('[^\w\s]' | ~(<) | ~(>),' ')
return df
输出:
File "<ipython-input-292-ac8369672f62>", line 3
df['Description'] = df['Description'].str.replace('[^\w\s]' | ~(<) | ~(>),' ')
^
SyntaxError: invalid syntax
我的数据框:
A B C
French house Phone. <phone_numbers>
English house email - <adresse_mail>
French apartment my name is Liam
French house Hello George!
English apartment Ethan, my phone is <phone_numbers>
良好的输出:
A B C
French house Phone <phone_numbers>
English house email <adresse_mail>
French apartment my name is Liam
French house Hello George
English apartment Ethan my phone is <phone_numbers>
【问题讨论】:
-
您能否添加所需的输出,因为您的正则表达式中似乎缺少引号?
-
@zipa 完成!谢谢