text_html_output_1.png
from plotly.subplots import make_subplots

import pandas as pd

import pandas as pd

import plotly.graph_objects as go

import plotly.graph_objects as go

healthsysdf = pd.read_csv('../input/world-bank-wdi-212-health-systems/2.12_Health_systems.csv')
healthsysdf = healthsysdf.drop(columns='Province_State')
healthsysdf = healthsysdf.drop(columns='Country_Region')
healthsysdf['Total_Gov_Spend'] = healthsysdf.apply(lambda row: row.Health_exp_pct_GDP_2016 / 100 * row.Health_exp_public_pct_2016, axis=1)
healthsysdf['Outofpocket_Spend'] = healthsysdf.apply(lambda row: row.Health_exp_pct_GDP_2016 / 100 * row.Health_exp_out_of_pocket_pct_2016, axis=1)
healthsysdf['Other_Spend'] = healthsysdf.apply(lambda row: row.Health_exp_pct_GDP_2016 - row.Total_Gov_Spend - row.Outofpocket_Spend, axis=1)
countrycodes = ['AFG', 'ALB', 'DZA', 'AND', 'AGO', 'ATG', 'ARG', 'ARM', 'AUS', 'AUT', 'AZE', 'BHS', 'BHR', 'BGD', 'BRB', 'BLR', 'BEL', 'BLZ', 'BEN', 'BTN', 'BOL', 'BIH', 'BWA', 'BRA', 'BRN', 'BGR', 'BFA', 'BDI', 'CPV', 'KHM', 'CMR', 'CAN', '', 'CAF', 'TCD', '', 'CHL', 'CHN', '', '', 'COL', 'COM', 'COD', 'COG', 'CRI', 'CIV', 'HRV', 'CUB', 'CYP', 'CZE', 'DNK', 'DJI', 'DMA', 'DOM', 'ECU', 'EGY', 'SLV', 'GNQ', 'ERI', 'EST', 'SWZ', 'ETH', '', 'FJI', 'FIN', 'FRA', '', 'GAB', 'GMB', 'GEO', 'DEU', 'GHA', 'GRC', '', 'GRD', '', 'GTM', 'GIN', 'GNB', 'GUY', 'HTI', 'HND', 'HUN', 'ISL', 'IND', 'IDN', 'IRN', 'IRQ', 'IRL', '', 'ISR', 'ITA', 'JAM', 'JPN', 'JOR', 'KAZ', 'KEN', 'KIR', '', 'KOR', '', 'KWT', 'KGZ', 'LAO', 'LVA', 'LBN', 'LSO', 'LBR', '', '', 'LTU', 'LUX', 'MDG', 'MWI', 'MYS', 'MDV', 'MLI', 'MLT', 'MHL', 'MRT', 'MUS', 'MEX', 'FSM', 'MDA', 'MCO', 'MNG', 'MNE', 'MAR', 'MOZ', 'MMR', 'NAM', 'NPL', 'NLD', '', 'NZL', 'NGA', 'NER', 'NGA', 'MKD', '', 'NOR', 'OMN', 'PAK', 'PLW', 'PAN', 'PNG', 'PRY', 'PER', 'PHL', 'POL', 'PRT', '', 'QAT', 'ROU', 'RUS', 'RWA', 'WSM', 'SMR', 'STP', 'SAU', 'SEN', 'SRB', 'SYC', 'SLE', 'SGP', '', 'SVK', 'SVN', 'SLB', '', 'ZAF', '', 'ESP', 'LKA', 'KNA', 'LCA', '', 'VCT', 'SDN', 'SUR', 'SWE', 'CHE', '', 'TJK', 'TZA', 'THA', 'TLS', 'TGO', 'TON', 'TTO', 'TUN', 'TUR', 'TKM', '', 'TUV', 'UGA', 'UKR', 'ARE', 'GBR', 'USA', 'URY', 'UZB', 'VUT', 'VEN', 'VNM', '', '', 'YEM', 'ZMB', 'ZWE']
healthsysdf['Country_Codes'] = countrycodes

bginfo = pd.read_csv('../input/undata-country-profiles/country_profile_variables.csv')
bginfo.rename(columns={'country': 'World_Bank_Name'}, inplace=True)
bginfo = bginfo.replace({'United States of America': 'United States', 'Viet Nam': 'Vietnam'})
healthsysdf = healthsysdf.replace({'Yemen, Rep.': 'Yemen'})
healthsysdf = pd.merge(healthsysdf, bginfo, on='World_Bank_Name', how='outer')
healthsysdf = healthsysdf.dropna(thresh=3)
badgdp = healthsysdf[healthsysdf['GDP: Gross domestic product (million current US$)'] < 0].index
healthsysdf.drop(badgdp, inplace=True)
healthsysdf.replace({'SouthernAsia': 'Asia', 'WesternAsia': 'Asia', 'EasternAsia': 'Asia', 'CentralAsia': 'Asia', 'South-easternAsia': 'Asia', 'WesternEurope': 'Europe', 'SouthernEurope': 'Europe', 'EasternEurope': 'Europe', 'NorthernEurope': 'Europe', 'NorthernAfrica': 'Africa', 'MiddleAfrica': 'Africa', 'WesternAfrica': 'Africa', 'EasternAfrica': 'Africa', 'SouthernAfrica': 'Africa', 'SouthAmerica': 'Americas', 'Caribbean': 'Americas', 'CentralAmerica': 'Americas', 'NorthernAmerica': 'Americas', 'Polynesia': 'Oceania', 'Melanesia': 'Oceania', 'Micronesia': 'Oceania'}, inplace=True)

total_exp = healthsysdf.sort_values('Health_exp_pct_GDP_2016', ascending = False)
top_ten_exp = total_exp.head(10)
total_exp = total_exp.sort_values('Health_exp_pct_GDP_2016')
low_ten_exp = total_exp.head(10)

fig = make_subplots(rows=1, cols=2, shared_yaxes=True)

fig.add_trace(
    go.Bar(x=top_ten_exp['World_Bank_Name'], y=top_ten_exp['Health_exp_pct_GDP_2016']),
    row=1, col=1
)

fig.add_trace(
    go.Bar(x=low_ten_exp['World_Bank_Name'], y=low_ten_exp['Health_exp_pct_GDP_2016']),
    row=1, col=2
)

fig.update_layout(
    title={
        'text': "Ten highest and lowest spenders",
        'y':0.9,
        'x':0.5,
        'xanchor': 'center',
        'yanchor': 'top'},
    plot_bgcolor= 'white',
    paper_bgcolor= 'white',
    yaxis_title="% of GDP spent on healthcare",
    showlegend=False,
    font=dict(
        family="Courier New, monospace",
        size=14,
        color="#7f7f7f"
    )
)
fig.show()

import plotly.graph_objects as go
import pandas as pd
fig = go.Figure(data=go.Choropleth(locations=healthsysdf['Country_Codes'], z=healthsysdf['Health_exp_pct_GDP_2016'], text=healthsysdf['World_Bank_Name'], colorscale='blues', autocolorscale=False, colorbar_tickprefix='% ', marker_line_color='darkgray', marker_line_width=0.5))
fig.update_layout(title_text='Percentage of GDP spent on Healthcare', font=dict(family='Courier New, monospace', size=14), geo=dict(showframe=False, showcoastlines=False, projection_type='equirectangular'))
fig.show()