I am new to python and trying to apply if-else condition over a dataframe.
If the ACCOUNT_LOGIN contains any special character create the csv under a ErrorFolder. else create the csv under ValidatedDataFolder
But the below is also creating a file under ValidatedDataFolder alongwith ErrorFolder even . How to acheive this validation of creating csv in different folders based on if-else condition?
dataframe ACCOUNT_LOGIN : [ AL&L@WA, ANGLIND, ASIGAFU ]
def validate(rowsofdataframe):
filename="TestFileSpclCharOp.txt"
if rowsofdataframe['ACCOUNT_LOGIN_1'].strip().isalnum()==False : #if any row contains any spcl character
output_error_file=os.path.join(errorPath,filename)
rowsofdataframe.to_csv(output_error_file,index=False)
val="Login contains special character.FAILED"
else :
validated_Files=os.path.join(foramttedPath,filename)
rowsofdataframe.to_csv(validated_Files,index=False)
val="All validation passed"
return val
dfwithcolumns['Status'] = dfwithcolumns.apply(validate, axis=1)
Aucun commentaire:
Enregistrer un commentaire