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

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -