salma
salma

Reputation: 3

In pandas dataframe, how to do regex replace for values of a string column

Using Jupyter, I have three gender categories in a column (m, male and female), and I want to replace "m" by "male", when I try this code, also "female" become "femaleale".

df['Gender'].replace(regex=[r'\bm\b'],value='male')

output

male
femaleale
male

...

Upvotes: 0

Views: 145

Answers (1)

Sree
Sree

Reputation: 983

df['Gender'].replace(['m'], ['male'], inplace=True)

You can try this!!

Upvotes: 2

Related Questions