Question

I am trying to remove everything in one column after the "-" as part of my clean up of a csv.

My regex works on notepad++ tests as I expect it to. But when I run this in my code it does not remove anything. I have tried numerous combinations and nothing is ever removed. Quite baffled.

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

Product Num Out (sample)
MX111-fxfxfxfxfv
Px999-gfgfgfgss
Was it helpful?

Solution

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

This worked, I don't quite understand why because I have not had to do this with my other edits for csv, for example

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

Anyone explain this?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top