RENGARAJ IT
RENGARAJ IT

Reputation: 29

Pandas Dataframe Replace Substring

For instance I have data similar to this

      name                    flag               seen_week_end
0    Mick Am Johnson         TRUE                 03/05/2017
1    Brian Ma Yeager          FALSE                 NaN
2    Maggie Alvarez       FALSE                NaN
3    Christine Ma Yin           FALSE                NaN

In the above dataframe I want to replace the word in name column

Am as Yan
Ma as Mu   

How to use dictionary and replace?

Upvotes: 0

Views: 45

Answers (1)

BENY
BENY

Reputation: 323226

Here is replace

df['name']=df['name'].replace({r'\bAm\b':'Yan',r'\bMa\b':'Mu'},regex=True)

Upvotes: 2

Related Questions