applying an email verification with a column condition in python

Viewed 13

I have the following columns.

 Person Id - EmailID- Email - Emailtype-
-18583-5435-natasha@gmail.com-P-
-13533-23145-john@georgeschool.com-W-
-35424-5784-smithedwardshotmail.com-P-
-35424-5785-smith.edwards@hardvardsuni.com-W-
-47815-8794-jill.townsendJohnsUniverty.com-W-

I am trying to apply an email verification on the email field however I only want to apply it on the email type W (work) only. This is my code so far

import re
import pandas as pd

data = pd.read_csv("data.csv", sep = ';',  error_bad_lines=False ) #Read file
value = data.iat[1,1] # load 1st value from table

data['EMail'] = data['EMail'].where(data['']data['EMail'].str.contains(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b') , 'Email field is invalid')
#check if any of the emails fields are invalid

#data['EZMail'] = data['EMail'].where(data['']data['EMail'].str.contains(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b') && data['']data['Emailtype'].str.contains('W') , 'Email field is invalid')  
#This is an example of what I was trying to achieve but I get an error.


data.to_csv(f'{value}DATA.csv', sep= ';', date_format='%Y%m%d', index=False)
#write data to file

As you can see above I only have part of the code but I am unable to figure out how apply the email verification on Emailtype 'W'. Possibly the use of the if condition?

Expected Output

- Person Id - EmailID- Email - Emailtype-
-18583-5435-natasha@gmail.com-P-
-13533-23145-john@georgeschool.com-W-
-35424-5784-smithedwardshotmail.com-P-
-35424-5785-smith.edwards@hardvardsuni.com-W-
-47815-8794-E-Mail field is invalid-W-

sry for the appearence but stackoverflow refused to accept my table format

0 Answers
Related