inclass_assignment_3
September 11, 2025
Name:
Kaggle link: [Link]
[2]: # QUESTION 1 (2)
# Import required libraries
import kagglehub
# Download latest version
path = kagglehub.dataset_download("yyxian/u-s-airline-traffic-data")
print("Path to dataset files:", path)
Using Colab cache for faster access to the 'u-s-airline-traffic-data' dataset.
Path to dataset files: /kaggle/input/u-s-airline-traffic-data
[23]: # QUESTION 2 (a) (5)
# Use the given dataset from Kaggle and show the first five rows with the␣
↪column names.
import pandas as pd
# Replace 'us_airline_traffic.csv' with the actual file name/path
df = pd.read_csv('/content/air [Link]')
print("Column names:", [Link]())
print("\nFirst five rows:")
print([Link](4))
Column names: ['Year', 'Month', 'Dom_Pax', 'Int_Pax', 'Pax', 'Dom_Flt',
'Int_Flt', 'Flt', 'Dom_RPM', 'Int_RPM', 'RPM', 'Dom_ASM', 'Int_ASM', 'ASM',
'Dom_LF', 'Int_LF', 'LF']
First five rows:
Year Month Dom_Pax Int_Pax Pax Dom_Flt Int_Flt Flt \
0 2003 1 43,032,450 4,905,830 47,938,280 785,160 57,667 842,827
1 2003 2 41,166,780 4,245,366 45,412,146 690,351 51,259 741,610
2 2003 3 49,992,700 5,008,613 55,001,313 797,194 58,926 856,120
3 2003 4 47,033,260 4,345,444 51,378,704 766,260 55,005 821,265
1
Dom_RPM Int_RPM RPM Dom_ASM Int_ASM ASM \
0 36,211,422 12,885,980 49,097,402 56,191,300 17,968,572 74,159,872
1 34,148,439 10,715,468 44,863,907 50,088,434 15,587,880 65,676,314
2 41,774,564 12,567,068 54,341,633 57,592,901 17,753,174 75,346,075
3 39,465,980 10,370,592 49,836,572 54,639,679 15,528,761 70,168,440
Dom_LF Int_LF LF
0 64.44 71.71 66.20
1 68.18 68.74 68.31
2 72.53 70.79 72.12
3 72.23 66.78 71.02
[25]: import os
from [Link] import drive
[Link] ("/content/drive")
Drive already mounted at /content/drive; to attempt to forcibly remount, call
[Link]("/content/drive", force_remount=True).
[28]: # QUESTION 2 (b) (10)
#Use Google Drive to load the dataset into a dataframe named 'air_traffic'
[Link]("/content/drive/MyDrive/Colab Notebooks")
QUESTION 3: Explore the dataset: Categorized the columns into: 1. Nominal, Ordinal, Interval,
and Ratio. (10) 2. Qualitative, Quantitative: Discrete and Continuous.(5)
[1]: # QUESTION 4: Explore the dataset using: info, shape, describe, column, index␣
↪(20)
# Write your findings about the data for each of these functions using a text␣
↪cell.
The dataset contains 17 columns and at least 4, likely more, rows.
The data types for many columns appear to be object (especially numeric columns␣
↪like 'Dom_Pax', 'Int_Pax', etc.), likely because they include commas, making␣
↪them strings. These will need to be converted to numeric for analysis.
There are no missing values indicated from the first few rows, but a full check␣
↪is needed.
Columns such as 'Year' and 'Month' are correctly interpreted as integers.
[1]: ['Year',
'Month',
'Dom_Pax',
'Int_Pax',
'Pax',
2
'Dom_Flt',
'Int_Flt',
'Flt',
'Dom_RPM',
'Int_RPM',
'RPM',
'Dom_ASM',
'Int_ASM',
'ASM',
'Dom_LF',
'Int_LF',
'LF']
[ ]: #Question 5(a): Manipulating Dataframes (5)
#Sort the data using "Number of Flights (Total)" in ascending order.
[25]: #Question 5(b): Manipulating Dataframes (8)
#Create a subset of the given dataset that consists of columns for domestic␣
↪flights info.
#Show the first 5 rows of the subset data
df['Flt'] = df['Flt'].[Link](',', '').astype(int)
df_sorted = df.sort_values(by='Flt', ascending=True)
print(df_sorted[['Year', 'Month', 'Flt']].head())
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/tmp/[Link] in <cell line: 0>()
3 #Show the first 5 rows of the subset data
4
----> 5 df_sorted = df.sort_values(by='Flt', ascending=True)
6
7 print(df_sorted[['Year', 'Month', 'Flt']].head(1))
NameError: name 'df' is not defined
[ ]: #Question 5(c): Manipulating Dataframes (5)
#Show info on the domestic flights that had more than 815,000 flights.
df['Dom_Flt'] = df['Dom_Flt'].[Link](',', '').astype(int)
high_dom_flights = df[df['Dom_Flt'] > 815000]
print(high_dom_flights)
3
[ ]: #Question 6: Data Cleaning (10)
#Show the mean, min (minimum) and (maximum) values for Domestic Air Travel␣
↪Passengers and Revenue Passenger-miles (Domestic).
df['Dom_Pax'] = df['Dom_Pax'].[Link](',', '').astype(int)
df['Dom_RPM'] = df['Dom_RPM'].[Link](',', '').astype(int)
dom_pax_mean = df['Dom_Pax'].mean()
dom_pax_min = df['Dom_Pax'].min()
dom_pax_max = df['Dom_Pax'].max()
dom_rpm_mean = df['Dom_RPM'].mean()
dom_rpm_min = df['Dom_RPM'].min()
dom_rpm_max = df['Dom_RPM'].max()
print("Domestic Air Travel Passengers (Dom_Pax):")
print(f"Mean: {dom_pax_mean:,.0f}")
print(f"Min: {dom_pax_min:,.0f}")
print(f"Max: {dom_pax_max:,.0f}")
print("\nDomestic Revenue Passenger-Miles (Dom_RPM):")
print(f"Mean: {dom_rpm_mean:,.0f}")
print(f"Min: {dom_rpm_min:,.0f}")
print(f"Max: {dom_rpm_max:,.0f}")
[ ]: df['Dom_RPM'] = df['Dom_RPM'].[Link](',', '').astype(float)
dom_rpm_mean = df['Dom_RPM'].mean()
[Link][df['Dom_RPM'] > dom_rpm_mean, 'Dom_RPM'] = dom_rpm_mean
print(df['Dom_RPM'])
QUESTION 7: Write a ‘reasonable’ research question that this dataset (10) can answer.
Submit the pdf