Python从字符串中删除特殊字符

2024-04-25 19:08:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的文字,我试图删除特殊字符显示在图像中使用Python。你知道吗

enter image description here

更新(粘贴文本):

145,Kevin,07/06/2018 15:12:37,Kevin,nan,nan,"have to clear outstanding tasks. 
check schedule "

我试过下面的方法,但没有成功

DF['col'] = re.sub("[^a-zA-Z]", " ", str(DF['col']))

有人能帮忙吗。谢谢。。你知道吗


Tags: to图像文本df粘贴checkhavecol
2条回答

我想你错过了a+

试试看

DF['col'] = re.sub("[^A-Za-z0-9]+", " ", str(DF['col']))
df['col'] = re.sub('[^A-Za-z0-9]+',' ',str(df['col'])

如果要将函数应用于所有行,可以执行以下操作:

df['col'] = df['col'].map(lambda x: re.sub('[^A-Za-z0-9]+',' ',str(df['col'])))

相关问题 更多 >