+ 1
How to split names in Pandas dataframe using regex.
The name is in the form Title. First_Name Middle_Name Last_Name in a dataframe
2 Answers
+ 3
I got those regex working now :)
with the help of the non-capturing groups, like: (?:regex)
df['title'] = df['fullname'].str.extract('(\w+\.) ')
df['firstname'] = df['fullname'].str.extract('(?:\w+\.\s)?(\w+)')
df['middlename'] = df['fullname'].str.extract('(?:\w+\.\s)?(?:\w+\s)(\w+)(?:\s[\w-]+)#x27;)
df['lastname'] = df['fullname'].str.extract('([\w-]+)#x27;)
+ 2
Hi
I was interested to solve this but it's not 100% complete... only the middle name is missing :P
I haven't come up with a viable way for that one yet... I'll think about it later.
https://code.sololearn.com/cBYTmzVN4yaH/#py
EDIT: code updated!