access_to_care, primary-prescribing, Health System Performance, Canada and Others

Justetc Social Services (non-profit)

Justetc Social Services (non-profit)Jan 31 · 5 min read

import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inlinefrom __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgetsaccess_to_care = pd.read_excel('../data/access-to-care.xls')
access_to_care.head()
png
# find all indicators
access_to_care.set_index(['Indicator'])
indicators = pd.Index(access_to_care['Indicator']).unique()

# find all years
years = access_to_care['Data year'].dropna().unique()
indicators[0], years('Inability to Pay for Medical Bills',
array(['2016', 2016, 'Not applicable', '2015', '2013'], dtype=object))# sort years
years = [ int(aYear) for aYear in years if (aYear != 'Not applicable') and len( str(aYear).split(' ')) <= 1 ]
years = sorted(years)
years

all_years = [0] + years
all_years[0, 2013, 2015, 2016, 2016]plt.rcParams['figure.figsize'] = [10, 10]
def plot_access_to_care(year, indicator, bubble_scale, all_years=all_years):
# print('year, indicator', year, indicator)
plt.ion()
f = plt.figure()
ax = f.gca()
f.show()

#indicator_data = health_status.loc[ (health_status['Indicator'] == indicators[0] ) ]
if ( year > 1 ):
indicator_data = access_to_care.loc[ (access_to_care['Indicator'] == indicator) & (access_to_care['Data year'] == year) ]
ax.scatter(indicator_data['Data year'], indicator_data['Region'], s=indicator_data['Value'] * bubble_scale )
plt.show()

else:
for aYear in all_years:
indicator_data = access_to_care.loc[ (access_to_care['Indicator'] == indicator) & (access_to_care['Data year'] == aYear) ]
ax.scatter(indicator_data['Data year'], indicator_data['Region'], s = indicator_data['Value'] * bubble_scale )
f.canvas.draw()# create the interactive interface
def f(x):
return x


indicator = interactive(f, x=indicators);
display(indicator)
indicator.result

year = interactive(f, x=all_years);
display(year)
year.result


bubble_scale = interactive(f, x=(0, 100, 1));
display(bubble_scale)
bubble_scale.resultinteractive(children=(Dropdown(description='x', options=('Inability to Pay for Medical Bills', 'Poor Weekend/E…



interactive(children=(Dropdown(description='x', options=(0, 2013, 2015, 2016, 2016), value=0), Output()), _dom…



interactive(children=(IntSlider(value=50, description='x'), Output()), _dom_classes=('widget-interact',))





50plot_access_to_care(year.result, indicator.result, bubble_scale.result)C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py:445: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.
% get_backend())
png
plt.rcParams['figure.figsize'] = [20, 10]
def plot_access_to_care_by_regions(year, indicator, bubble_scale, all_years=all_years):
#print('year, indicator', year, indicator)
plt.ion()
f = plt.figure()
ax = f.gca()
f.show()

#indicator_data = health_status.loc[ (health_status['Indicator'] == indicators[0] ) ]

if ( year > 1 ):
#indicator_data = indicator_data [ indicator_data['Data year'] == year]
indicator_data = access_to_care.loc[ (access_to_care['Indicator'] == indicator) & (access_to_care['Data year'] == year) ]
#print(indicator_data)
ax.scatter(indicator_data['Region'], indicator_data['Value'], s=indicator_data['Value'] * bubble_scale )
plt.show()

else:
for aYear in all_years:
indicator_data = access_to_care.loc[ (access_to_care['Indicator'] == indicator) & (access_to_care['Data year'] == aYear) ]
ax.scatter(indicator_data['Region'], indicator_data['Value'], s = indicator_data['Value'] * bubble_scale )
f.canvas.draw()print('Select parameter to visualize across countries over years')
# create the interactive interface
def f(x):
return x


indicator = interactive(f, x=indicators);
display(indicator)
indicator.result

year = interactive(f, x=all_years);
display(year)
year.result


bubble_scale = interactive(f, x=(0, 100, 1));
display(bubble_scale)
bubble_scale.resultSelect parameter to visualize across countries over years



interactive(children=(Dropdown(description='x', options=('Inability to Pay for Medical Bills', 'Poor Weekend/E…



interactive(children=(Dropdown(description='x', options=(0, 2013, 2015, 2016, 2016), value=0), Output()), _dom…



interactive(children=(IntSlider(value=50, description='x'), Output()), _dom_classes=('widget-interact',))





50plot_access_to_care_by_regions(year.result, indicator.result, bubble_scale.result)
png
plt.rcParams['figure.figsize'] = [20, 10]
def plot_access_to_care_by_countries(year, indicator, bubble_scale, selected_countries, all_years=all_years):
#print('year, indicator', year, indicator)
plt.ion()
f = plt.figure()
ax = f.gca()
f.show()

#indicator_data = health_status.loc[ (health_status['Indicator'] == indicators[0] ) ]

if ( year > 1 ):
#indicator_data = indicator_data [ indicator_data['Data year'] == year]
indicator_data = access_to_care.loc[ (access_to_care['Indicator'] == indicator) & (access_to_care['Data year'] == str(year) ) & (access_to_care['Type of region'] == 'Country' ) ]
#print(indicator_data)

if ( len(selected_countries) > 1 ):
indicator_data = indicator_data[ indicator_data['Region'].isin(selected_countries)]

ax.scatter(indicator_data['Region'], indicator_data['Value'], s=indicator_data['Value'] * bubble_scale )
plt.show()

else:
for aYear in all_years:
indicator_data = access_to_care.loc[ (access_to_care['Indicator'] == indicator) & (access_to_care['Data year'] == str(aYear) ) & (access_to_care['Type of region'] == 'Country' ) ]
if ( len(selected_countries) > 1 ):
indicator_data = indicator_data[ indicator_data['Region'].isin(selected_countries)]

#print(indicator_data)
ax.scatter(indicator_data['Region'], indicator_data['Value'], s = indicator_data['Value'] * bubble_scale )
f.canvas.draw()countries = access_to_care[ access_to_care['Type of region'] == 'Country' ]['Region']
countries = sorted (countries.unique())
#countries = ['Canada'] + countries
if 'Canada' in countries:
countries = ['Canada'] + countries

#countriesprint('Select parameters to visualize across countries over years\n')
# create the interactive interface
def f(x):
return x

print('Select chart type:')
chart_types = ['Bubble', 'Bar', 'Pie', 'Line']
chart = interactive(f, x=chart_types);
display(chart)
chart.result

print('Select Indicator')
indicator_country = interactive(f, x=indicators);
display(indicator_country)
indicator_country.result

print('Select Year: 0 = all years')
year_country = interactive(f, x=all_years);
display(year_country)
year_country.result

print('Select bubble size')
bubble_scale_country = interactive(f, x=(0, 100, 1));
display(bubble_scale_country)
bubble_scale_country.result

print('Max country count to compare with')
country_count = interactive(f, x=range(1, 20));
display(country_count)
country_count.result

print('Select countries')
print('Compare with Canada')
all_countries = interactive(f, x=True);
display(all_countries)
all_countries.result

country_0 = interactive(f, x = countries);
country_1 = interactive(f, x = countries);
#country_str = "var%d = interactive(f, x = countries)"
display(country_0)
display(country_1)
country_0.result

print('Compare with Canada')
compare_canada = interactive(f, x=True);
display(compare_canada)
compare_canada.resultSelect parameters to visualize across countries over years

Select chart type:



interactive(children=(Dropdown(description='x', options=('Bubble', 'Bar', 'Pie', 'Line'), value='Bubble'), Out…


Select Indicator



interactive(children=(Dropdown(description='x', options=('Inability to Pay for Medical Bills', 'Poor Weekend/E…


Select Year: 0 = all years



interactive(children=(Dropdown(description='x', options=(0, 2013, 2015, 2016, 2016), value=0), Output()), _dom…


Select bubble size



interactive(children=(IntSlider(value=50, description='x'), Output()), _dom_classes=('widget-interact',))


Max country count to compare with



interactive(children=(Dropdown(description='x', options=(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16…


Select countries
Compare with Canada



interactive(children=(Checkbox(value=True, description='x'), Output()), _dom_classes=('widget-interact',))



interactive(children=(Dropdown(description='x', options=('Belgium', 'Chile', 'Denmark', 'Estonia', 'Finland', …



interactive(children=(Dropdown(description='x', options=('Belgium', 'Chile', 'Denmark', 'Estonia', 'Finland', …


Compare with Canada



interactive(children=(Checkbox(value=True, description='x'), Output()), _dom_classes=('widget-interact',))





Truecountry_0.result'Belgium'selected_countries = []
if (all_countries.result == False):
selected_countries = [country_0.result, country_1.result]

#print(year_country.result, indicator_country.result, bubble_scale_country.result)
plot_access_to_care_by_countries(year_country.result, indicator_country.result, bubble_scale_country.result, selected_countries)
#print(country_0, country_1)
png
access_to_care.loc[  (access_to_care['Indicator'] == indicators[0])  & (access_to_care['Data year'] == '2013') & (access_to_care['Type of region'] == 'Country')     ]
png

Appendix

"""
print('Select countries')
for i in range(country_count.result):
#country_str = interactive(f, x = countries);
country_str = "var%d = interactive(f, x = countries)"
display(country)
country.result
"""

for i in range(country_count.result):
country_str = "var%d = interactive(f, x = countries)" %(i)

exec(country_str)
country_str

for i in [0, 2]:
'var' + str(i)

Permanent link to this article: https://bangla.sitestree.com/access_to_care-primary-prescribing-health-system-performance-canada-and-others/