How to use pandas extract to remove string in a pandas column

Viewed 36

I have this dataframe:

d = pd.DataFrame({'test':['test?_Apple','test?_Banana', 'test?_limon']})

And I want to remove the test?_ string from test columns values to get this:

d = pd.DataFrame({'test':['Apple','Banana', 'limon']})

I am trying:

d['test'] = d['test'].str.extract(r'test?_(.*)')

but it returns NAN

Can someone help me on this one?

1 Answers

Escape ? because special regex character:

d['test'] = d['test'].str.extract(r'test\?_(.*)')
Related