Reposting a previous question for clarity. I'm trying to use the email-validator library in python to validate a list of emails in an excel document. Here is a photo of what my data resembles and the validation column output I'd like to create: photo
When I run the following code on a single email, the code works just fine. I get "Valid" when the email is valid and "Invalid" when it is not. The following successfully prints "Valid":
import email_validator
from email_validator import validate_email, EmailNotValidError
testemail = "[email protected]"
try:
emailobject = validate_email(testemail)
testemail = emailobject.email
print("Valid")
except EmailNotValidError:
print("Invalid")
But I want to run this validation technique on a pandas dataframe. When I write a function to apply to the emails column of my dataframe, I consistently get the following error:
RecursionError: maximum recursion depth exceeded
The following function always returns this error, even though my test email column consists of just three email rows:
def validate_email(em):
try:
emailobject = validate_email(em)
em = emailobject.email
print("Valid")
except EmailNotValidError:
print("Invalid")
df["Validation"] = df["Email"].apply(validate_email)
Why am I getting this error? It's only three rows of data; I don't understand why this error would occur. If I am doing something wrong or if there is a better way to use the email-validator library on my dataframe, I would love to know. I greatly appreciate any and all help.
Thank you.
validate_email(em)in the first snippet? And why do you name your functionvalidate_emailin the second?