This python script will generate four variant emails based on the company officers name and domain names.
If the officer name is "John Smith" and his company's domain name is "example.com", then the script is required to return four emails with the formats as follow:-
Email 1: john.smith@example.com
Email 2: jsmith@example.com
Email 3: info@example.com
Email 4: sales@example.com
I think the requirement is fairly clear and requires no further explanations.
import pandas as pd
df = pd.read_excel(r"C:\Users\Yusuf_08039508010\App_Data.xlsx")
df
Create function to perform the magics.
# Defining the email functions...
# Email 1 - john.smith@example.com
def email_1(name, website):
return name.replace(' ', '.').lower() +"@"+ website.lower()
# Email 2 - jsmith@example.com
def email_2(name, website):
return name.split(' ')[0][0].lower() + name.split(' ')[1].lower()+"@"+ website.lower()
# Email 3 - info@example.com
def email_3(website):
return 'info' +"@"+ website.lower()
# Email 4 - sales@example.com
def email_4(website):
return 'sales' +"@"+ website.lower()
Apply the functions to the columns.
# df['col_3'] = df.apply(lambda x: f(x.col_1, x.col_2), axis=1)
# df['col_3'] = df.apply(lambda x: f(x['col_1'], x['col_2']), axis=1)
df['Email 1'] = df.apply( lambda x : email_1(x['Company Staff Name'], x['Company Domain Name']), axis=1 )
df['Email 2'] = df.apply( lambda x : email_2(x['Company Staff Name'], x['Company Domain Name']), axis=1 )
df['Email 3'] = df.apply( lambda x : email_3(x['Company Domain Name']), axis=1 )
df['Email 4'] = df.apply( lambda x : email_4(x['Company Domain Name']), axis=1 )
df
That is it!
No comments:
Post a Comment