In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
from datetime import datetime
import numpy as np
from matplotlib.ticker import FixedLocator, FixedFormatter
#import seaborn as sns
to_colors = lambda x : x/255.
In [2]:
ls
In [3]:
df_ind_items = pd.read_csv('raw_data_items.csv',header=0,index_col=0,parse_dates=0)
df_ind_items.head()
Out[3]:
In [4]:
df_ind_items.index
Out[4]:
In [5]:
df_infl_items = df_ind_items.pct_change(periods=12)*100
mask_rows_infl = df_infl_items.index.year >= 2000
df_infl_items = df_infl_items[mask_rows_infl]
df_infl_items.tail()
Out[5]:
In [6]:
tt = df_infl_items.copy()
tt['month'] = tt.index.month
tt['year'] = tt.index.year
tt.head()
Out[6]:
In [7]:
tt.to_csv('infl_items.csv')
df_infl_items.rename(columns = dic)
tt = df_infl_items.copy() tt['month'] = tt.index.month tt['year'] = tt.index.year melted_df = pd.melt(tt,id_vars=['month','year']) melted_df.head()
In [8]:
df_infl_items['min'] = df_infl_items.apply(min,axis=1)
df_infl_items['max'] = df_infl_items.apply(max,axis=1)
df_infl_items['mean'] = df_infl_items.apply(np.mean,axis=1)
df_infl_items['mode'] = df_infl_items.quantile(q=0.5, axis=1)
df_infl_items['10th'] = df_infl_items.quantile(q=0.10, axis=1)
df_infl_items['90th'] = df_infl_items.quantile(q=0.90, axis=1)
df_infl_items['25th'] = df_infl_items.quantile(q=0.25, axis=1)
df_infl_items['75th'] = df_infl_items.quantile(q=0.75, axis=1)
In [9]:
df_infl_items.tail()
Out[9]:
df_infl_items['month'] = df_infl_items.index.month df_infl_items['year'] = df_infl_items.index.year
In [10]:
df_infl_items.head()
Out[10]:
In [11]:
print(df_infl_items.describe())
with plt.style.context('https://gist.githubusercontent.com/rhiever/d0a7332fe0beebfdc3d5/raw/223d70799b48131d5ce2723cd5784f39d7a3a653/tableau10.mplstyle'): for column in df_infl_items.columns[:-2]:
#if column in ['date']:
# continue
plt.figure()
plt.hist(df_infl_items[column].values)
plt.title(column)
#plt.savefig('{}.png'.format(column))
In [12]:
len(df_infl_items)
Out[12]:
In [13]:
df_infl_items.columns
Out[13]:
In [14]:
df_infl_items['month_order'] = range(len(df_infl_items))
month_order = df_infl_items['month_order']
max_infl = df_infl_items['max'].values
min_infl = df_infl_items['min'].values
mean_infl = df_infl_items['mean'].values
mode_infl = df_infl_items['mode'].values
p25th = df_infl_items['25th'].values
p75th = df_infl_items['75th'].values
p10th = df_infl_items['10th'].values
p90th = df_infl_items['90th'].values
inflEA = df_infl_items['76451'].values
In [15]:
year_begin_df = df_infl_items[df_infl_items.index.month == 1]
year_begin_df;
In [16]:
year_beginning_indeces = list(year_begin_df['month_order'].values)
year_beginning_indeces
Out[16]:
In [17]:
year_beginning_names = list(year_begin_df.index.year)
year_beginning_names
Out[17]:
In [18]:
month_order;
In [19]:
blue3 = map(to_colors, (24, 116, 205)) # 1874CD
wheat2 = map(to_colors, (238, 216, 174)) # EED8AE
wheat3 = map(to_colors, (205, 186, 150)) # CDBA96
wheat4 = map(to_colors, (139, 126, 102)) # 8B7E66
firebrick3 = map(to_colors, (205, 38, 38)) # CD2626
gray30 = map(to_colors, (77, 77, 77)) # 4D4D4D
In [ ]:
In [20]:
fig, ax1 = plt.subplots(figsize=(15,7))
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.xlim(-5,200)
plt.grid(False)
##ax2 = ax1.twiny()
plt.ylim(-5, 10)
#ax3 = ax1.twinx()
plt.yticks(range(-4, 10, 2), [r'{}'.format(x)
for x in range(-4, 10, 2)], fontsize=10);
plt.grid(axis='both', color='wheat', linewidth=1.5, alpha = .5)
plt.title('HICP inflation, annual rate of change, Jan 2000 - March 2016\n\n', fontsize=20);
In [ ]: