The yearly percentage of flights cancelled for each reason (A=carrier, B=weather, C= NAS, D=security)
%matplotlib inline
from math import pi
import pandas
import collections
import matplotlib.pyplot as plt
import numpy as np
from bokeh.plotting import output_notebook, show
from bokeh import *
from bokeh.io import reset_output,output_file
from bokeh.core.properties import value
from bokeh.palettes import Category20c
from bokeh.transform import cumsum
from bokeh.models.widgets import Panel, Tabs
output_notebook()
datac=pandas.read_csv("query5.csv")
xList=[]
yList=[]
dataList=[]
for k in datac.itertuples():
x={}
y= (getattr(k,"Year"))
a= int(getattr(k,"Acanc"))
b= int(getattr(k,"Bcanc"))
c= int(getattr(k,"Ccanc"))
d= int(getattr(k,"Dcanc"))
yList.append(y)
x["A: carrier"]=a
x["B: weather"]=b
x["C: NAS"]=c
x["D: security"]=d
xList.append(x)
count=yList[0]
tabList=[]
for elem in xList:
data = pandas.Series(elem).reset_index(name='value').rename(columns={'index':'type'})
data['angle'] = data['value']/data['value'].sum() * 2*pi
data['color'] = Category20c[len(x)]
p = figure(plot_height=350, title="Statistic on Cancellation Typology",
tools="hover", tooltips="@type: @value", x_range=(-0.5, 1.0))
p.wedge(x=0, y=1, radius=0.4,
start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),
line_color="white", fill_color='color', legend='type', source=data)
p.axis.axis_label=None
p.axis.visible=False
p.grid.grid_line_color = None
tab = Panel(child=p, title=str(count))
tabList.append(tab)
count+=1
tabs = Tabs(tabs=tabList)
show(tabs)