【发布时间】:2022-01-22 21:15:41
【问题描述】:
我正在尝试将数据框中的特殊字符替换为非重音字符或其他字符。
我可以用一个替换
df['col_name'] = df.col_name.str.replace('?','j')
这变成了“?”到 'j' - 但是 - 我似乎无法弄清楚如何更改多个..
我有一个想要更改的特殊字符列表。我试过用字典,但它似乎不起作用
the_reps = {'?','j'}
df1 = df.replace(the_reps, regex = True)
这给了我在位置 0 处没有可替换的错误
编辑:
这是有效的——虽然它可能不是那么漂亮:
df[col]=df.col.str.replace('old char','new char')
df[col]=df.col.str.replace('old char','new char')
df[col]=df.col.str.replace('old char','new char')
df[col]=df.col.str.replace('old char','new char')...
每一个..
【问题讨论】:
-
试试
df['column'] = df['column'].str.replace('.*@+.*', 'replacement')。我发现:stackoverflow.com/questions/34702338/… -
这能回答你的问题吗? Replace Multiple Values of columns
-
我认为我遇到的问题是 - 我想用特定的替换字符替换某些字符 - 而不仅仅是所有字符都具有相同或空格或其他内容。
-
你能查一下this answer@PorscheAdams
-
我仍然在位置 0 得到错误,没有可替换的内容 -