Home > Blockchain >  How to iterate (validate_email) through a dataframe column
How to iterate (validate_email) through a dataframe column

Time:06-19

How to iterate through the email column(x) with the lines below

validate_email(x, check_mx=True)
validate_email(x, verify=True)

#pip install pyDNS
#pip install validate_email

import pandas as pd 
from validate_email import validate_email

# initialize list of lists
data = [['[email protected]','True','True'], ['[email protected]','True','False'], ['[email protected]','False','False']]
 
# Create the pandas DataFrame
df = pd.DataFrame(data, columns=['email', 'check_mx', 'verify'])
 
# print dataframe.
df

Output should look like the image below:

enter image description here

CodePudding user response:

There is a package for that:

from validate_email import validate_email
df['is_valid_email'] = df['email'].apply(lambda x:validate_email(x))

This will create a column with a value if the email address is valid

  • Related