大熊猫的正则表达式没有删除任何列?

时间:2014-05-03 17:01:38

标签: regex pandas ipython-notebook python-3.4

我正在尝试删除“ - ”之后的一列中的所有内容,作为清理csv的一部分。

我的正则表达式适用于记事本++测试,正如我所期望的那样。但是当我在我的代码中运行它时,它不会删除任何东西。我尝试了很多组合,没有删除任何东西。相当困惑。

df['Product Num Out'].replace("-[^-]*$","", regex=True)
Also tried
df['Product Num Out'].str.replace("-[^-]*$","")

Product Num Out (sample)
MX111-fxfxfxfxfv
Px999-gfgfgfgss

1 个答案:

答案 0 :(得分:0)

df['Product Num Out'] = df['Product Num Out'].replace("-[^-]*$","", regex=True)

这很有用,我不太明白为什么因为我没有用csv的其他编辑来做这个,例如

df['Abuse/NFF'].replace("-", "Faulty", inplace=True)

有人解释这个吗?