1

I'm planning to validate columns in my dataframe as follows...

def validateCol1(val):
    #validate
    #write invalid entries to my error tracking list with row reference

df['col1'].apply(validateCol1)

But although that passes the column value to my function, I want to be able to access the row where the error occured. Does anyone know how I could do that?

1 Answer 1

2

You can apply the lambda function to the row instead of only on a single column:

df.apply(lambda x: validateCol(x), axis=1)

Thus in the validateCol function you can access value in column 1 using x['col1'] and also access other columns in the row.

Sign up to request clarification or add additional context in comments.

Comments

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.