【发布时间】:2022-07-19 21:44:39
【问题描述】:
我的数据框中有 3 列,我想只从下面提到的列中删除那些特殊字符:
,.-=[]{}/?,.()&^%$#@!;~`*
我已经尝试了下面的代码,但它不能正常工作
regex = re.compile('[,.-=[]{}\/?,.<>()*&^%$#@!;~`]')
s=[]
for i in range(len(df1)):
L = df1.loc[i,'Vendor Name']
s.append(regex.sub('', L))
df1['Vendor Name']=s
此代码没有删除指定的特殊字符,我无法找出问题所在。
【问题讨论】:
-
可能是
df1['Vendor Name'].str.replace(r'[][,.={}/?,.<>()*&^%$#@!;~`-]+', '', regex=True)?你还需要删除\char 吗?
标签: python pandas regex special-characters