Reputation: 1317
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?
Upvotes: 1
Views: 418
Reputation: 91
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.
Upvotes: 2