application_vnd.jupyter.stderr_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

df = pd.read_csv('../input/flights.csv')
df = df[df['MONTH'] == 1]

airlineList = df['AIRLINE'].unique()
airlineList = airlineList.tolist()

def calculate_Airline_D_Delays(airlineName):
    d = df[df['AIRLINE'] == airlineName]
    d = d[d['DEPARTURE_DELAY'] > 0]
    li = d['DEPARTURE_DELAY'].tolist()
    li = np.array(li)
    return li
def calculate_Airline_A_Delays(airlineName):
    d = df[df['AIRLINE'] == airlineName]
    d = d[d['ARRIVAL_DELAY'] > 0]
    li = d['ARRIVAL_DELAY'].tolist()
    li = np.array(li)
    return li

avgAirlineDD = []
avgAirlineAD = []
for a in airlineList:
    avgAirlineDD.append(calculate_Airline_D_Delays(a).mean())
    avgAirlineAD.append(calculate_Airline_A_Delays(a).mean())

n_groups = len(airlineList)
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.25
opacity = 0.4
error_config = {'ecolor': '0.3'}
rects1 = plt.bar(index, avgAirlineDD, bar_width, alpha=opacity, color='b', error_kw=error_config, label='Departure')
rects2 = plt.bar(index + bar_width, avgAirlineAD, bar_width, alpha=opacity, color='r', error_kw=error_config, label='Arrival')
plt.margins(0.01)
plt.xlabel('Airlines')
plt.ylabel('Average Delays (Min)')
plt.title('Comparison of Departure/Arrival Delays')
plt.xticks(index + bar_width / 2, airlineList)
plt.legend(loc='upper left')
plt.tight_layout()
plt.show()