문제

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
도움이 되었습니까?

해결책

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top