Eurostat Statistics part V: hospital beds per capita

hospital_2015_beds

[Datasource: Eurostat]

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import re


df = pd.read_csv('eurostat/eurostat_beds.csv',sep=';',
                 skiprows=5,decimal=',',
                 names=['GEO','2004','2005','2006','2007',
                        '2008','2009','2010','2011','2012',
                        '2013','2014','2015'],
                 nrows=35,engine='python',na_values=[':'])

df2 = pd.read_csv('eurostat/eurostat_psy_beds.csv',sep=';',
                  skiprows=5,decimal=',',names=['GEO','2004',
                                                '2005','2006','2007','2008',
                                                '2009','2010','2011','2012',
                                                '2013','2014','2015'],
                  nrows=35,engine='python',na_values=[':'])

regex = re.compile(r'Former.Y.*')

df['GEO']= df['GEO'].str.replace(regex,'Macedonia')
df2['GEO']= df['GEO'].str.replace(regex,'Macedonia')

df.set_index('GEO',inplace=True)
df2.set_index('GEO',inplace=True)

countries = list(df.index)
xticks = [countries[i][0:3] for i in range(len(countries))]

for year in df.columns:
    plt.figure(figsize=(18,12))
    plt.title('Hospital beds per 100.000 habitants {}'.format(year))
    df = df.sort_values(by=year,ascending=False)
    barlist = plt.bar(np.arange(len(countries)) - 0.2,
                      df[year],width=0.4,color='r',label='Somatic')
    plt.bar(np.arange(len(countries)) + 0.2 ,
            df2[year],width=0.4,color='g',label='Psychiatric')
    plt.axhline(df[year].mean(),color='r',ls='dashed',lw=3,
                label='Mean Somatic')
    plt.axhline(df2[year].mean(),color='g',ls='dashed',lw=3,
                label='Mean Psychiatric')
    plt.xticks(range(len(countries)),xticks)
    plt.legend(loc='upper right')
    plt.xlabel('$Datasource:Eurostat$')
    plt.savefig('hospital_' + year + '_beds.jpg',format='jpg')
plt.show()

About swdevperestroika

High tech industry veteran, avid hacker reluctantly transformed to mgmt consultant.
This entry was posted in Big Data, Data Analytics, Data Driven Management, Numpy, Python, Statistics and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s