【发布时间】:2021-02-12 21:28:06
【问题描述】:
正则表达式替换不起作用的原因是什么?我已尝试确保没有多余的空间。
df.column
0 Test_With_Him
1 And_another option with him
2 and_another reason with her
replacement = {'_':' ',Test With': 'test with', 'and another': 'And another& AND'}
df['column'] = df.column.replace('\s+',' ' , regex=True).str.strip().replace(replacement, regex=True)
当我做df.loc[df['column']=="and another reason with her"] 时,什么都没有改变。
【问题讨论】:
-
你没有把结果赋值回去,
df.column = df.column.... -
我是在原始代码中完成的,但忘记在此处输入,抱歉。还是不行
-
无法复制,我得到的是
And another& AND reason with her而不是and another reason with her -
你知道它失败的任何原因吗?
标签: python python-3.x regex pandas