<jupyter_start><jupyter_text><jupyter_code>#import tools from library
from google.colab import files

#upload car.data from local machine
uploaded = files.upload()
import pandas as pd

gdp = pd.read_csv('Single_Payer_GDP.csv')
per_capita = pd.read_csv('SinglePayer Per Capita.csv')
cost_2018 =pd.read_csv('GDPandPerCapita2018.csv')
print(gdp.shape)
gdp.head()
gdp.columns.tolist()
#Columns to use
columns = ['LOCATION','Country','Year','Value']

gdp = gdp[columns]

gdp.head()
print(per_capita.shape)
per_capita.head()
per_capita = per_capita[columns]
per_capita.head()
gdp.rename(columns={'Value':'Cost_GDP'}, inplace=True)
per_capita.rename(columns={'Value':'Cost_Per_Capita'}, inplace=True)
merged = pd.merge(gdp,per_capita, on = ['LOCATION','Country', 'Year'])

print(merged.shape)
merged.head()
merged.dtypes
merged['LOCATION'].value_counts()
mean_US = merged.groupby('Year').mean()

mean_US['Country'] = 'Mean With US'

mean_US = mean_US.reset_index()

mean_US
cond = merged['Country'] != 'United States'
mean_sp = merged[cond].groupby('Year').mean()
mean_sp['Country'] = 'Mean Single Payer'
mean_sp = mean_sp.reset_index()

mean_sp
final = pd.concat([merged, mean_US, mean_sp], join='inner', ignore_index=True)
final.tail()
import plotly.express as px

fig1 = px.scatter(final, x="Year", y="Cost_GDP", color='Country')

fig1.update_traces(mode='lines+markers')

fig1.update_layout(
    title_text = 'Single-payer Healthcare is Signifigantly Less Expensive',
    annotations=[dict(
        showarrow=False,
        x= 0.05,
        y= 1.05,
        text='Comparison of the United States and Countries with a Single Payer Funding Model', 
        xref='paper',
        yref='paper'
        )])

fig1.update_yaxes(ticksuffix="%", title_text='Percentage of Gross Domestic Product')

fig1.show()
import plotly.express as px

fig2 = px.scatter(final, x="Year", y="Cost_Per_Capita", color='Country')

fig2.update_traces(mode='lines+markers')

fig2.update_layout(
    title_text = 'Single-payer Healthcare is Less Expensive',
    annotations=[dict(
        showarrow=False,
        x= 0.05,
        y= 1.05,
        text='Comparison of the United States and Countries with a Single Payer Funding Model', 
        xref='paper',
        yref='paper'
        )])


# Prefix y-axis tick labels with dollar sign
fig2.update_yaxes(tickprefix="$", title_text='Per Capita Cost, USD, Current PPP')

fig2.show()
cond = merged['Country'] == 'United States'

us_only = merged[cond]
us_only.head()
fig5 = px.scatter(us_only, x="Year", y="Cost_Per_Capita")

fig5.update_traces(mode='lines+markers')

fig5.update_layout(
    title_text = 'Healthcare is Getting A Lot More Expensive',
    annotations=[dict(
        showarrow=False,
        x= 0,
        y= 1.05,
        text='United States Annual Health Expenditure(Per Person)', 
        xref='paper',
        yref='paper'
        )])


# Prefix y-axis tick labels with dollar sign
fig5.update_yaxes(tickprefix="$", title_text='Per Capita Cost, USD, Current PPP')

fig5.show()
import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig4 = make_subplots(specs=[[{"secondary_y": True}]])

fig4.add_trace(go.Scatter(x=us_only['Year'], y=us_only['Cost_Per_Capita'],
                          mode='lines+markers',
                          name='Per Capita Cost, USD, Current PPP'))
fig4.add_trace(go.Scatter(x=us_only['Year'], y=us_only['Cost_GDP'],
                          mode='lines+markers',
                          name='Percentage of Gross Domestic Product'),
                          secondary_y=True)


fig4.update_yaxes(tickprefix="$",
                  secondary_y=False, 
                  title_text='Per Capita Cost, USD, Current PPP')
fig4.update_yaxes(ticksuffix="%", 
                  secondary_y=True,
                  title_text='Percentage of Gross Domestic Product')

fig4.show()

cond1 = cost_2018['Unit Code'] == 'USD'
cond2 = cost_2018['Unit Code'] != 'USD'
capita_18 = cost_2018[cond1].drop(columns='Unit Code').rename(columns={'Value':'Per_Capita'})
gdp_18 = cost_2018[cond2].drop(columns='Unit Code').rename(columns={'Value':'GDP'})
capita_18.head()
gdp_capita = pd.merge(gdp_18, capita_18,on=['LOCATION', 'Country'])
gdp_capita = gdp_capita.sort_values(by=['Per_Capita'])
gdp_capita.head()
fig3 = px.bar(gdp_capita, 
              x='Country', 
              y='Per_Capita', 
              color='GDP', 
              labels={'Per_Capita':'Per Capita Cost, USD, Current PPP',
                      'GDP':'Percentage of GDP'},
              color_continuous_scale='Viridis',              
              title='United States has the most Expensive Healthcare')

# Prefix y-axis tick labels with dollar sign
fig3.update_yaxes(tickprefix="$")

fig3.update_layout(annotations=[dict(
        showarrow=False,
        x= 0.05,
        y= 1.05,
        text='2018 Per Capita Health Expenditures', 
        xref='paper',
        yref='paper'
        )])

fig3.show()
!pip install chart_studio
import chart_studio

username = 'dggasque' # your username
api_key = '<KEY>' # your api key - go to profile > settings > regenerate key
chart_studio.tools.set_credentials_file(username=username, api_key=api_key)
chart_studio.plotly.plot(fig1, filename = 'GDP', auto_open=True)
chart_studio.plotly.plot(fig2, filename = 'Per Capita', auto_open=True)

chart_studio.plotly.plot(fig3, filename = '208 Bar Capita', auto_open=True)
chart_studio.plotly.plot(fig5, filename = 'US Per Capita', auto_open=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13901508268217336, 'fraction_numerical': 0.017445029983645284, 'mean_word_length': 3.7736339982653946, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '210636', 'license': 'MIT', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1858, 'n_words': 388, 'path': 'Cost_Comparison.ipynb', 'repo_name': 'dggasque/healthcare_analysis', 'size': '5518'}