I have a simple/flat dataset that looks like...
columnA columnB columnC
value1a value1b value1c
value2a value2b value2c
...
valueNa valueNb valueNc
Although the structure is simple, it's tens of millions of rows deep and I have 50+ columns.
I need to validate that each value in a row conforms with certain format requirements. Some checks are simple (e.g. isDecimal, isEmpty, isAllowedValue etc) but some involve references to other columns (e.g. does columnC = columnA / columnB) and some involve conditional validations (e.g. if columnC = x, does columnB contain y).
I started off thinking that the most efficient way to validate this data was by applying lambda functions to my dataframe...
df.apply(lambda x: validateCol(x), axis=1)
But it seems like this can't support the full range of conditional validations I need to perform (where specific cell validations need to refer to other cells in other columns).
Is the most efficient way to do this to simply loop through all rows one-by-one and check each cell one-by-one? At the moment, I'm resorting to this but it's taking several minutes to get through the list...
df.columns = ['columnA','columnB','columnC']
myList = df.T.to_dict().values() #much faster to iterate over list
for row in myList:
#validate(row['columnA'], row['columnB'], row['columnC'])
Thanks for any thoughts on the most efficient way to do this. At the moment, my solution works, but it feels ugly and slow!