Dataset is from here.
In [46]:
import pandas as pd
import plotly.express as px
data = (
pd.read_excel('../assets/prorogation.xlsx', skiprows=8, skipfooter=3)
.assign(
ProrogationDays=lambda x: x['Calendar Days Between Date of New Session and Prorogation of Previous Session'],
ProrogationDate=lambda x: x['Prorogation Date'].shift(1),
Election=lambda x: x['General Election Before Session'].fillna('N')
)
# Since...
.loc[lambda x: x.ProrogationDate > pd.datetime(1950, 1, 1)]
)
data.info()
In [3]:
fig = px.bar(data, x='ProrogationDate', y='ProrogationDays', color='Election')
with open('../iframes/prorogation_full.html', 'w') as f:
f.write(fig.to_html())
fig
In [44]:
fig = px.bar(data[data.Election == 'N'], x='ProrogationDate', y='ProrogationDays')
with open('../iframes/prorogation_not_election.html', 'w') as f:
f.write(fig.to_html())
fig
In [45]:
fig = (
data
.assign(IsCurrentProrogation=lambda x: x['ProrogationDate'] == x['ProrogationDate'].iloc[-1])
.loc[lambda x: x.Election == 'N']
.groupby('IsCurrentProrogation')
['ProrogationDays'].agg(['mean', 'std'])
.reset_index()
.rename(columns={'mean': 'Length of Prorogation'})
.pipe(px.bar, x='IsCurrentProrogation', y='Length of Prorogation', error_y='std', labels=['Past', 'Current'])
)
with open('../iframes/prorogation_barchart.html', 'w') as f:
f.write(fig.to_html())
fig
In [47]:
col = 'Calendar Days Between Date of New Session and Prorogation of Previous Session'
d = data[data.Election == 'N']
uq = d[col].quantile(0.75)
lq = d[col].quantile(0.25)
iqr = uq - lq
upper_bound = uq + 3.0 * iqr
In [49]:
(d[col].max() - uq) / iqr
Out[49]:
In [31]:
33/20
Out[31]:
In [21]:
px.box(d, y=col)