I'm converting values to float from multiple columns in a dataset concurrently in a loop, where I try to skip bad rows with a ValueError exception
My data has been loaded with a structure that enables me to loop over it as such
A_floated = []
B_floated = []
for i in range(len(data)):
A = data[i]["column_A"]
B = data[i]["column_B"]
try:
A = float(A)
A_floated.append(A)
B = float(B)
B_floated.append(B)
except(ValueError):
continue
I want the exception to encompass both A and B, so that if any of them contains a bad row, all of them will be skipped for this i, so that len(A_floated) == len(B_floated). Right now, I can only figure out how to skip bad rows on an individual-column basis, but then I end up with floated columns of different lengths.
How can this be done?