TDM 10200: Project 12 — 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.

Questions

Question 1 (2 points)

  1. In the previous project, you created 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. Now let us use this class as a base class. Create a new subclass called ScheduledFlight. Add 2 more attributes to this new subclass: CRSDepTime and CRSArrTime.

  2. Add a method called is_ontime() to the class, which returns a boolean value that indicates if the flight departs on time and arrives on 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 ScheduledFlight class instances. (When you are finished, you should have a list of 100 ScheduledFlight instances.)

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

Question 3 (2 points)

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

  2. Calculate the total number of flights that were on time, for each destination airport.

Question 4 (2 points)

  1. Add a method called is_delayed() to the class that indicates if the flight was delayed (either had a departure delay or an arrival delay).

  2. Calculate the total number of delayed flights, for each destination airport.

Question 5 (2 points)

  1. Create a subclass of your own, with at least one method, and then use the dataset to get some meaningful information that uses this subclass.

Project 12 Assignment Checklist

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

    • firstname-lastname-project12.ipynb.

  • Python file with code and comments for the assignment

    • firstname-lastname-project12.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.