I have a column in my dataframe for email addresses. Sometimes the field contains multiple emails separated by ;
EMAIL COMMENT
[email protected] Example Comment
[email protected]; [email protected]
[email protected]; [email protected]; [email protected] Another comment
My goal is to have the EMAIL
field only have 1 email and append all the extra emails to the COMMENT
column. Here is my ideal output:
EMAIL COMMENT
[email protected] Example Comment
[email protected] [email protected]
[email protected] Another comment|[email protected]; [email protected]
Here is my code thus far:
df['EMAIL2'] = df['EMAIL'].str.split('; ', 1).str[0] # Split on `; ` if exist and only keep first email
df['COMMENT'] += "|Emails=" + df['EMAIL'].str.split('; ', 1).str[1]
df['EMAIL'] = df['EMAIL2'] # Set Email = Email2