I am trying to replace strings in a dataframe if the whole string equals another string. I do not want to replace substrings.
So:
If I have df:
Index Name Age
0 Joe 8
1 Mary 10
2 Marybeth 11
and I want to replace "Mary" when the whole string matches "Mary" with "Amy" so I get
Index Name Age
0 Joe 8
1 Amy 10
2 Marybeth 11
I'm doing the following:
df['Name'] = df['Name'].apply(lambda x: x.replace('Mary','Amy'))
My understanding from searching around is that the defaults of replace set regex=False and replace should look for the whole value in the dataframe to be "Mary". Instead I'm getting this result:
Index Name Age
0 Joe 8
1 Amy 10
2 Amybeth 11
What am I doing wrong?