Domanda

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
È stato utile?

Soluzione

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?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top