Guest User

Untitled

a guest
Dec 13th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. `import csv
  2. with open('826766072_T_ONTIME.csv') as csv_infile: #import and open CSV
  3. reader = csv.DictReader(csv_infile)
  4. total_delay = 0
  5. flight_count = 0
  6. flight_numbers = []
  7. delay_totals = []
  8. dest_list = [] #create empty list of destinations
  9. for row in reader:
  10. if row['ORIGIN'] == 'BOS': #only take flights leaving BOS
  11. if row['FL_NUM'] not in flight_numbers:
  12. flight_numbers.append(row['FL_NUM'])
  13. if row['DEST'] not in dest_list: #if the dest is not already in the list
  14. dest_list.append(row['DEST']) #append the dest to dest_list
  15. for number in flight_numbers:
  16. for row in reader:
  17. if row['ORIGIN'] == 'BOS': #for flights leaving BOS
  18. if row['FL_NUM'] == number:
  19. if float(row['CANCELLED']) < 1: #if the flight is not cancelled
  20. if float(row['DEP_DELAY']) >= 0: #and the delay is greater or equal to 0 (some flights had negative delay?)
  21. total_delay += float(row['DEP_DELAY']) #add time of delay to total delay
  22. flight_count += 1 #add the flight to total flight count
  23. for row in reader:
  24. for number in flight_numbers:
  25. delay_totals.append(sum(row['DEP_DELAY']))`
Add Comment
Please, Sign In to add comment