In [151]:
# https://twitter.com/anthonyncutler/status/1268600602130616320
In [152]:
%%time
dataset_name = "W19_comb"
df_list = [ "BES_Panel" ]
%matplotlib inline
%run BES_header.py {dataset_name} {df_list}
if "id" in BES_Panel.columns:
BES_Panel = BES_Panel.set_index("id").sort_index()
(var_type, cat_dictionary, new_old_col_names, old_new_col_names) = get_small_files(data_subfolder, encoding)
# get full set of inferred "cross wave" auth-lib/left-right values and ages
pan_dataset_allr_values = pd.read_csv(BES_small_data_files + "pan_dataset_allr_valuesW19"+".csv")
pan_dataset_ages = pd.read_pickle(BES_small_data_files + "pan_dataset_ages"+".zip", compression='zip')
In [153]:
import numpy as np
import holoviews as hv
from holoviews import dim
hv.extension('bokeh')
In [154]:
df = pd.read_stata("E:\\BES_analysis_data\\Linked\\BESExpertSurveyTrendFile2014-2019.dta")
In [155]:
lib_auth_replace_dict = { df["libauthGreen"].cat.categories[x]:x for x in range(0,11)}
lib_auth_replace_dict["Don't know"] = np.nan
lib_auth_replace_dict["No position"] = np.nan
left_right_replace_dict = lib_auth_replace_dict.copy()
del left_right_replace_dict["Libertarian"],left_right_replace_dict["Authoritarian"],
left_right_replace_dict["Right"] = 10
left_right_replace_dict["Left"] = 0
party_list = ['Lab', 'Con', 'LibDem', 'UKIP', 'Brexit', 'Green', 'SNP', 'Plaid']
In [156]:
libauth = pd.DataFrame()
leftright = pd.DataFrame()
for party in party_list:
leftright[party] = df["leftright"+party].astype('object').replace(left_right_replace_dict).groupby(df["year"]).mean()
libauth[party] = df["libauth"+party].replace(lib_auth_replace_dict).groupby(df["year"]).mean()
In [157]:
years = hv.Dimension(('year','Year'), range=(1,4))
hv_dict = {}
year_list = [2014,2015,2017,2019]
# year_ind = 1
for year in year_list:
year_means = pd.concat([leftright.loc[year],libauth.loc[year]],axis=1)
year_means.columns = [ "leftright","libauth" ]
set_len = year_means.shape[0]
data = year_means
points = hv.Scatter(data).opts(xlim=(0,10),ylim=(0,10),color='k', marker='diamond',
size=10,alpha=.5,height=500,width=500,
xlabel ="Economic Left (0) - Economic Right (10)",
ylabel ="Libertarian (0) - Authoritarian (10)")
labels = hv.Labels({('x', 'y'): data, 'text': year_means.index}, ['x', 'y'], 'text')
overlay = (points * labels)
overlay.opts(opts.Labels(text_font_size='10pt', xoffset=0.2,yoffset=0.1),
opts.Points(color='black', size=5))
hv_dict[year]=overlay
# year_ind = year_ind+1
hv.output(backend='bokeh',fig='png', holomap='widgets')
hm = hv.HoloMap(hv_dict, kdims=['years'])
hm
Out[157]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
Comments
comments powered by Disqus