I have used try - except and it works, but I was wondering if we can perform a similar function with for - if and else.
# check for "NA" values, ignore the entries which have them
# index: DeptTime = 4,Deptdelay = 15, Arrtime = 6, ArrDelay = 14
for index in flight_data[1:]:
try:
x_dept.append(int(index[4]))
y_dept.append(int(index[15]))
x_arr.append(int(index[6]))
y_arr.append(int(index[14]))
except ValueError:
pass
For instance, can we do something like this to get the exactly same answer?
# check for "NA" values, ignore the entries which have them
# index: DeptTime = 4,Deptdelay = 15, Arrtime = 6, ArrDelay = 14
for index in flight_data[1:]:
if index[4] =='NA' or index[15] == 'NA' or index[14] =='NA' or index[6] == 'NA':
pass
else:
x_dept.append(int(index[4]))
y_dept.append(int(index[15]))
x_arr.append(int(index[6]))
y_arr.append(int(index[14]))