In [54]:
import pandas as pd
In [55]:
#Read information from the csv file into pandas
airline_data=pd.read_csv("/Users/candacegrant/Desktop/IS362 Date Acquisition/IS362 Project 1.csv")
In [56]:
#Analysis of the first 5 rows to check the validity of the data.
airline_data.head()
Out[56]:
In [57]:
#I calculated the percent of Alaska Airlines flights that were delayed for each of the 5 destinations
# The delayed flights divided by the total flights times 100 gives you the percent of total flights delayed.
# The results of the calculation are set to a new column called "Alaska_Percent_Delay"
airline_data['Total_Alaska_Flights'] = airline_data['Alaska_On_Time'] + airline_data['Alaska_Delay']
airline_data['Alaska_Percent_Delay'] = (airline_data['Alaska_Delay'] / airline_data['Total_Alaska_Flights']) * 100
airline_data['Alaska_Percent_Delay']
Out[57]:
In [58]:
# The same proces is followed for finding the per cent of AM West flights delayed.
# Set the results of the calculation to a new column called "AM West_Percent_Delayed"
airline_data['Total_AMWest'] = airline_data['AM WEST_Delay'] + airline_data['AM WEST_On_Time']
airline_data['AMWest_Percent_Delay'] = (airline_data['AM WEST_Delay'] / airline_data['Total_AMWest']) * 100
airline_data['AMWest_Percent_Delay']
Out[58]:
In [61]:
# I can visually compare the delays of the two airlines at each destination
# It is clear that AM West airline has a greater percent of flights delayed at every destination.
airline_data[['Alaska_Percent_Delay', 'AMWest_Percent_Delay']]
Out[61]:
In [64]:
for index, row in airline_data.iterrows():
if row["Alaska_Percent_Delay"] > row["AMWest_Percent_Delay"]:
airline_data.loc[index, 'Most_Delayed_Airline'] = 'Alaska'
else:
airline_data.loc[index, 'Most_Delayed_Airline'] = 'AMWest'
airline_data['Most_Delayed_Airline']
Out[64]:
In [65]:
airline_data
Out[65]:
Since the number of flights travelled among both airlines was not the same it was helpful to analyze the data based on the percentage of flights that were delayed among both airlines. The results show that AMWest had the greates percentage of delays among the five cities samples for the data set. Since a greter percentage of AWWest flights are delayed it is a reasonable to assume that Alaska airlines would be the more reliable for passengers flying to Los Angelos, Pheonix, San Diego, Sanfrancisco and Seattle.