Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `import csv
- with open('826766072_T_ONTIME.csv') as csv_infile: #import and open CSV
- reader = csv.DictReader(csv_infile)
- total_delay = 0
- flight_count = 0
- flight_numbers = []
- delay_totals = []
- dest_list = [] #create empty list of destinations
- for row in reader:
- if row['ORIGIN'] == 'BOS': #only take flights leaving BOS
- if row['FL_NUM'] not in flight_numbers:
- flight_numbers.append(row['FL_NUM'])
- if row['DEST'] not in dest_list: #if the dest is not already in the list
- dest_list.append(row['DEST']) #append the dest to dest_list
- for number in flight_numbers:
- for row in reader:
- if row['ORIGIN'] == 'BOS': #for flights leaving BOS
- if row['FL_NUM'] == number:
- if float(row['CANCELLED']) < 1: #if the flight is not cancelled
- if float(row['DEP_DELAY']) >= 0: #and the delay is greater or equal to 0 (some flights had negative delay?)
- total_delay += float(row['DEP_DELAY']) #add time of delay to total delay
- flight_count += 1 #add the flight to total flight count
- for row in reader:
- for number in flight_numbers:
- delay_totals.append(sum(row['DEP_DELAY']))`
Add Comment
Please, Sign In to add comment