DEV Community

kohiladevi31
kohiladevi31

Posted on

Python Name lookup

I have firstname,lastname,Middlename,fullname in a dataframe. I have a list of 500 titles like MR,MR.,DDS,D.d.d,MD,m.d., So I have to identify whether these titles are present in firstname or last name and full name, if they are, I have to drop it. Please help me with this.Thanks

Full_name First_Name Middle_name Last_Name
Ramesh DDS., kumar, Ramesh kumar DDS.
Suresh DDS, Kumar, G Suresh G Kumar DDS
Anjali DDS, devi, Anjali devi DDS
Aruna DDS, Kumari, G. Aruna G. Kumari DDS
Christin DDS, Selva, G. Christin G. Christin DDS
Rathana DDS, Kumari, Rathana Kumari DDS
JOhn DDS, peter, R JOHN C DDS R Kumar DDS
Raj DDS, Kumar, Raj Jothi DDS
Siva DDS, Jothi, Siva Nathan DDS
Senthil DDS, Nathan, Senthi dev DDS
Prasath DDS, dev, Prasath Kumar DDS
anil, Kumar C DDS, Anil Kumar
varun DDS, Dhavan S, varun Dhavan DDS
Vinoth, Kanna C DDS, Vinoth Kanna
DDS joshi, mani H, Joshi DDS Mani
DDS kamal, kanna H, Kamal DDS Kanna

Top comments (1)

Collapse
 
m4sk4r4 profile image
Gabriel

I am new here and I am not sure if here is correct place for this question(maybe reddit is a better place), but did you know to use regular expression?

English is not my native language so I hope I have understood you correctly

--

import re

names = """
Ramesh DDS., kumar, Ramesh kumar DDS.
Suresh DDS, Kumar, G Suresh G Kumar DDS
Anjali DDS, devi, Anjali devi DDS
Aruna DDS, Kumari, G. Aruna G. Kumari DDS
Christin DDS, Selva, G. Christin G. Christin DDS
Rathana DDS, Kumari, Rathana Kumari DDS
JOhn DDS, peter, R JOHN C DDS R Kumar DDS
Raj DDS, Kumar, Raj Jothi DDS
Siva DDS, Jothi, Siva Nathan DDS
Senthil DDS, Nathan, Senthi dev DDS
Prasath DDS, dev, Prasath Kumar DDS
anil, Kumar C DDS, Anil Kumar
varun DDS, Dhavan S, varun Dhavan DDS
Vinoth, Kanna C DDS, Vinoth Kanna
DDS joshi, mani H, Joshi DDS Mani
DDS kamal, kanna H, Kamal DDS Kanna
"""

pattern = r'(MR|MR.|DDS|D.d.d|MD|m.d.)'

print(re.sub(pattern, '', names))