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 |
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: |
Questions
Question 1 (2 points)
-
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. -
Add a function called
get_arrdelay()
to the class, which gets the arrival delay time.
Question 2 (2 points)
-
Create a DataFrame named
myDF
, to store data from the2014.csv
data set. It suffices to import (only) the columns listed below, and to (only) read in the first 100 rows. Although we provide thecolumns_to_read
, please make (and use) a dictionary ofcol_types
like we did in Question 1 of Project 10. -
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)
-
Create an empty dictionary named
delays_dest
. Then use a for loop to assign values todelays_dest
from the 100 Flight objects. -
Calculate the average arrival delay time for each destination airport, and save the result to a dictionary named
average_delays
Question 4 (2 points)
-
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. -
Run the function using the 100 Flight instances from Question 2 as input.
Question 5 (2 points)
-
Update the class
Flight
to add a method namedget_depdelay()
to the class. -
Create a function called
dep_avg_delays
, similar to thearr_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). -
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. |