I have this dataset
ID Name
101 DR. ADAM SMITH
102 BEN DAVIS
103 MRS. ASHELY JOHNSON
104 DR. CATHY JONES
105 JOHN DOE SMITH
Desired Output
ID Name
101 ADAM SMITH
102 BEN DAVIS
103 ASHELY JOHNSON
104 CATHY JONES
105 JOHN DOE SMITH
I need to get rid of the prefix I tried df['Name'] = df['Name'].replace(to_replace = 'DR. ', value = '')I repeated the same code for all prefixes, but I have when I do it nothing happens. Any reason for this?
Thank you in advance.
>Solution :
Use a regular expression to match the first word if it ends with ..
df['Name'] = df['Name'].str.replace(r'^[A-Z]+\.\s+', '', regex=True)