The cope snippet for this chart follows.
import numpy as np import pandas as pd import matplotlib.pyplot as plt import sys sys.path.append( '../bin' ) plt.style.use('../bin/markgraph.mplstyle') # --- downloaded data files from the AEC pp2010 = './Data/e2010-prepoll-stats-19-08.csv' pp2013 = './Data/e2013-prepoll-stats-07-09.csv' pp2016 = './Data/20160702_WEB_Prepoll_Report.csv' pp2019 = './Data/20190518_WEB_Pre-poll_Report_FE2019.csv' # --- build a comparative table from the AEC files elections = ['2010-08-21', '2013-09-07', '2016-07-02', '2019-05-18'] years = [e[0:4] for e in elections] files = [globals()[y] for y in ['pp' + x for x in years]] for (y, f, e) in zip (years, files, elections): print(y) df = pd.read_csv(f) # - delete n initial columns - sum to daily totals - calculate index if y == '2010': n = 2 elif y in ['2013', '2016']: n = 3 elif y == '2019': n = 4 s = df.drop(labels=df.columns[0:n], axis=1).sum() s.index = pd.to_datetime(arg=s.index.values, dayfirst=True) s.index = s.index - np.datetime64(e, 'D') # - build up the comparative table for each election if y == '2010': table = pd.DataFrame([s], index=[y]).T else: table = table.reindex(index=pd.Index.union(table.index, s.index)) table[y] = s # --- tidy up - present as cumsum - metric is millions - make index an int table = (table / 1_000_000).fillna(0).cumsum() table.index = (table.index.values / np.timedelta64(1, 'D')).astype(int) # --- plot the comparatve table ax = table.plot() ax.set_title('Cumulative Pre-Poll Numbers') ax.set_xlabel('Days prior to the Election') ax.set_ylabel('Millions pre-polled') fig = ax.figure fig.set_size_inches(8, 4) fig.tight_layout(pad=1) fig.text(0.99, 0.0025, 'marktheballot.blogspot.com.au', ha='right', va='bottom', fontsize='x-small', fontstyle='italic', color='#999999') fig.savefig('./Graphs/Pre-poll.png', dpi=125) plt.close()
Mate after last night you are a genius.
ReplyDeleteWell done
A bit lucky too - the polling data had clearly been manipulated (probably smoothed or something) - so it was suspect - but I was as surprised as anyone at the scale of the polling failure.
Delete