0

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.

4
  • What is validate_email(em) in the first snippet? And why do you name your function validate_email in the second? Commented Nov 9, 2022 at 18:17
  • It's a method from the email-validator library. Sorry for the confusion, just updated my code with the import email_validator code in there. Commented Nov 9, 2022 at 18:24
  • def validate_email(em) Calls itself for ever. What else could happen? , change the name in the def to resolve. Also your funtion is not returning anything just prints Commented Nov 9, 2022 at 18:42
  • Ugh, dumb mistake. That's why we ask questions haha. It is resolved now, thank you. Commented Nov 9, 2022 at 19:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.