In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
from datetime import datetime
import numpy as np
In [2]:
ls
In [3]:
df_ind_ctry = pd.read_csv('raw_data_countries.csv',header=0,index_col=0,parse_dates=0)
df_ind_ctry.head()
Out[3]:
In [4]:
df_ind_ctry.index
Out[4]:
In [5]:
mask_rows_ind = df_ind_ctry.index.year >= 1999
mask_rows_ind;
In [6]:
df_ind_ctry = df_ind_ctry[mask_rows_ind]
df_ind_ctry.head()
Out[6]:
In [7]:
## Compute annual inflation rates
In [8]:
df_infl_ctry = df_ind_ctry.pct_change(periods=12)*100
mask_rows_infl = df_infl_ctry.index.year >= 2000
df_infl_ctry = df_infl_ctry[mask_rows_infl]
df_infl_ctry.tail()
Out[8]:
df_infl_ctry.rename(columns = dic)
tt = df_infl_ctry.copy() tt['month'] = tt.index.month tt['year'] = tt.index.year melted_df = pd.melt(tt,id_vars=['month','year']) melted_df.head()
In [9]:
df_infl_ctry['min'] = df_infl_ctry.apply(min,axis=1)
df_infl_ctry['max'] = df_infl_ctry.apply(max,axis=1)
df_infl_ctry['mean'] = df_infl_ctry.apply(np.mean,axis=1)
df_infl_ctry['mode'] = df_infl_ctry.quantile(q=0.5, axis=1)
df_infl_ctry['10th'] = df_infl_ctry.quantile(q=0.10, axis=1)
df_infl_ctry['90th'] = df_infl_ctry.quantile(q=0.90, axis=1)
df_infl_ctry['25th'] = df_infl_ctry.quantile(q=0.25, axis=1)
df_infl_ctry['75th'] = df_infl_ctry.quantile(q=0.75, axis=1)
In [10]:
df_infl_ctry.head()
Out[10]:
df_infl_ctry['month'] = df_infl_ctry.index.month df_infl_ctry['year'] = df_infl_ctry.index.year
In [11]:
df_infl_ctry.tail()
Out[11]:
In [12]:
print(df_infl_ctry.describe())
with plt.style.context('https://gist.githubusercontent.com/rhiever/d0a7332fe0beebfdc3d5/raw/223d70799b48131d5ce2723cd5784f39d7a3a653/tableau10.mplstyle'): for column in df_infl_ctry.columns[:-2]:
#if column in ['date']:
# continue
plt.figure()
plt.hist(df_infl_ctry[column].values)
plt.title(column)
#plt.savefig('{}.png'.format(column))
In [13]:
len(df_infl_ctry)
Out[13]:
In [14]:
df_infl_ctry.columns
Out[14]:
In [15]:
df_infl_ctry['month_order'] = range(len(df_infl_ctry))
month_order = df_infl_ctry['month_order']
max_infl = df_infl_ctry['max'].values
min_infl = df_infl_ctry['min'].values
mean_infl = df_infl_ctry['mean'].values
mode_infl = df_infl_ctry['mode'].values
p25th = df_infl_ctry['25th'].values
p75th = df_infl_ctry['75th'].values
p10th = df_infl_ctry['10th'].values
p90th = df_infl_ctry['90th'].values
inflEA = df_infl_ctry['76451'].values
In [16]:
year_begin_df = df_infl_ctry[df_infl_ctry.index.month == 1]
year_begin_df;
In [17]:
year_beginning_indeces = list(year_begin_df['month_order'].values)
year_beginning_indeces
Out[17]:
In [18]:
year_beginning_names = list(year_begin_df.index.year)
year_beginning_names
Out[18]:
In [19]:
month_order
Out[19]:
In [20]:
#import seaborn as sns
In [22]:
fig, ax1 = plt.subplots(figsize=(15, 7))
# Create the bars showing highs and lows
#plt.bar(month_order, max_infl - min_infl, bottom=min_infl,
# edgecolor='none', color='#C3BBA4', width=1)
plt.bar(month_order, p90th - p10th, bottom=p10th,
edgecolor='none', color='#C3BBA4', width=1)
# Create the bars showing average highs and lows
plt.bar(month_order, p75th - p25th, bottom=p25th,
edgecolor='none', color='#9A9180', width=1);
#annotations={month_order[50]:'Dividends'}
plt.plot(month_order, inflEA, color='#5A3B49',linewidth=2 );
plt.plot(month_order, mode_infl, color='wheat',linewidth=2,alpha=.3);
plt.xticks(year_beginning_indeces,
year_beginning_names,
fontsize=10)
#ax2 = ax1.twiny()
plt.xticks(year_beginning_indeces,
year_beginning_names,
fontsize=10);
plt.xlim(-5,200)
plt.grid(False)
##ax2 = ax1.twiny()
plt.ylim(-5, 14)
#ax3 = ax1.twinx()
plt.yticks(range(-4, 15, 2), [r'{}'.format(x)
for x in range(-4, 15, 2)], fontsize=10);
plt.grid(axis='both', color='wheat', linewidth=1.5, alpha = .5)
plt.title('HICP innflation, annual rate of change, Jan 2000 - March 2016\n\n', fontsize=20);
In [ ]: