I have a dataframe with a column with individuals' names:
name
Mr. Salmon
Mr Salmon
Ms. Salmon
Mrs. Salmon
Mrs Salmon
...
I would like to remove all the honorifics. I compiled the following regex at regex101.com and confirmed all the matches.
(^[Mm]([Rr]|[Ss]|[Xx]|[Rr][Ss]|[Ii][Ss]+)\.?\s)|(^[Mm][Ii][Ss][Tt][Ee][Rr]\.?\s)|(^[Mm][Ii][Ss]+[Uu][Ss]\.?\s)
I am using the replace method on the names dataframe to remove the regex matches with nothing. I am using the following code:
names_nohf = names.replace(r'(^[Mm]([Rr]|[Ss]|[Xx]|[Rr][Ss]|[Ii][Ss]+)\.?\s)|(^[Mm][Ii][Ss][Tt][Ee][Rr]\.?\s)|(^[Mm][Ii][Ss]+[Uu][Ss]\.?\s)', regex = True)
This, however, is not returning the desired names and is in fact making no changes at all. Could someone please point me to the right direction?
replace("old", "new")- and then uses empty string as new string.Nonethen it doesn't work but if I put empty string then it works