How much longer is this proroguation?

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()


<class 'pandas.core.frame.DataFrame'>
Int64Index: 63 entries, 54 to 122
Data columns (total 10 columns):
Session                                                                          63 non-null object
Date of Meeting                                                                  63 non-null datetime64[ns]
Prorogation Date                                                                 56 non-null datetime64[ns]
Dissolution Date                                                                 18 non-null datetime64[ns]
General Election Before Session                                                  12 non-null object
Election Date                                                                    12 non-null object
Calendar Days Between Date of New Session and Prorogation of Previous Session    63 non-null float64
ProrogationDays                                                                  63 non-null float64
ProrogationDate                                                                  63 non-null datetime64[ns]
Election                                                                         63 non-null object
dtypes: datetime64[ns](4), float64(2), object(4)
memory usage: 5.4+ KB

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


Outlier Definitions


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]:
13.5

In [31]:
33/20


Out[31]:
1.65

In [21]:
px.box(d, y=col)