Python 从列中的字符串中删除特殊字符和子字符串
我对这一切都很陌生。我正在使用Python和pandas库处理一个大型数据集,如:Python 从列中的字符串中删除特殊字符和子字符串,python,pandas,substring,Python,Pandas,Substring,我对这一切都很陌生。我正在使用Python和pandas库处理一个大型数据集,如: date text 0 Jul 31 2020 "test sentence numerouno" 1 Jul 31 2020 (second sentence) unonumero 2 Jul 31 2020 testuno sentence!!! 现在我正在寻找
date text
0 Jul 31 2020 "test sentence numerouno"
1 Jul 31 2020 (second sentence) unonumero
2 Jul 31 2020 testuno sentence!!!
现在我正在寻找一个函数/循环,它删除一组已定义的子字符串和特殊字符
因此,为了具体说明并坚持示例,我想从“text”列中删除所有特殊字符“
(
)
!
,以及子字符串uno
因此,输出应如下所示:
date text
0 Jul 31 2020 test sentence numero
1 Jul 31 2020 second sentence numero
2 Jul 31 2020 test sentence
感谢您的帮助!您可以使用以下模式:
df['text'] = df['text'].str.replace(r'[^ A-Za-z]+|uno','')
print(df.text)
0 test sentence numero
1 second sentence numero
2 test sentence
Name: text, dtype: object
看啊,好的。非常感谢!