TDM 10200: Project 11 — Spring 2024

Motivation: Learning classes in Python

Scope: Object Oriented Python

Scope: Python, python class, pandas

Reading and Resources

Dataset

/anvil/projects/tdm/data/flights/2014.csv

You need to use 2 cores for your Jupyter Lab session for Project 11 this week.

You can use pd.set_option('display.max_columns', None) if you want to see all of the columns in a very wide data frame.

We added six new videos to help you with Project 11. BUT the example videos are about a data set with beer reviews. You need to (instead) work on the flight data given here: /anvil/projects/tdm/data/flights/2014.csv

Questions

Question 1 (2 points)

  1. Create a class named Flight, which contains attributes for the flight number, origin airport ID, destination airport ID, departure time, arrival time, departure delay, and arrival delay.

  2. Add a function called get_arrdelay() to the class, which gets the arrival delay time.

Question 2 (2 points)

  1. Create a DataFrame named myDF, to store data from the 2014.csv data set. It suffices to import (only) the columns listed below, and to (only) read in the first 100 rows. Although we provide the columns_to_read, please make (and use) a dictionary of col_types like we did in Question 1 of Project 10.

  2. Load the data from myDF into the Flight class instances. (When you are finished, you should have a list of 100 Flight instances.)

columns_to_read = [
    'DepDelay', 'ArrDelay', 'Flight_Number_Reporting_Airline', 'Distance',
    'CarrierDelay', 'WeatherDelay',
    'DepTime', 'ArrTime', 'Origin',
    'Dest', 'AirTime'
]

Question 3 (2 points)

  1. Create an empty dictionary named delays_dest. Then use a for loop to assign values to delays_dest from the 100 Flight objects.

  2. Calculate the average arrival delay time for each destination airport, and save the result to a dictionary named average_delays

Question 4 (2 points)

  1. Create a function called arr_avg_delays based on the steps from Question 3. This function should have a collection of Flight objects as the input. The function should output a dictionary containing the average arrival delays for each destination airport.

  2. Run the function using the 100 Flight instances from Question 2 as input.

Question 5 (2 points)

  1. Update the class Flight to add a method named get_depdelay() to the class.

  2. Create a function called dep_avg_delays, similar to the arr_avg_delays. This function should have a collection of Flight objects as the input. It should use the average departure delay (instead of the average arrival delays), and it should do this for each origin airport (instead of each destination airport).

  3. Run the function using the 100 Flight instances from Question 2 as input.

Project 11 Assignment Checklist

  • Jupyter Lab notebook with your code, comments and output for the assignment

    • firstname-lastname-project11.ipynb.

  • Python file with code and comments for the assignment

    • firstname-lastname-project11.py

  • Submit files through Gradescope

Please make sure to double check that your submission is complete, and contains all of your code and output before submitting. If you are on a spotty internet connection, it is recommended to download your submission after submitting it to make sure what you think you submitted, was what you actually submitted.

In addition, please review our submission guidelines before submitting your project.