python - skip an error row in a for loop -
i iterating through each row in csv file , choose/calculate rows meet condition. however, when there error in row, stops loop. there way tell python skip error , move next row? use try
function did not work. code is
try(row['bas'] = float(row['close ask']) - float(row['close bid']))
the error 1 of cell string , cannot converted float
you want like:
for row in csv_file: try: x = float(row['close ask']) - float(row['close bid']) except valueerror: continue else: # keep going doing x ...
Comments
Post a Comment