In [1]:
"""
This NB is used to develop the .py script that makes csv files with
aggregate uncertainty in ../output/agg_uncert
"""
import os
import pandas as pd
import scipy.stats as stats
import scipy.optimize as opt
import numpy as np
In [2]:
input_dir = "../output/indiv_uncert/"
series = 'HICP' #'UN' #'HICP'
year = '2014'
quarter = 'Q4'
input_file = series + year + quarter + '.csv'
fname = input_dir + input_file
print(input_file)
In [3]:
if not os.path.isfile(fname):
print(input_file + ' does not exist in ' + input_dir)
else:
print("it's all good!")
In [5]:
df = pd.read_csv(fname,)
df.head()
Out[5]:
In [6]:
# Define the aggregation calculations
aggregations = {
'point': { #
'1.mean': 'mean', #
'2.std': 'std', #
'3.IQR': lambda x: x.quantile(.75) - x.quantile(.25)
},
'GA_std': {#
# 'mean': 'mean',
'median': 'median'
},
'ZL_std': {#
# 'mean': 'mean',
'median': 'median'
},
'Hist_std': {#
# 'mean': 'mean',
'median': 'median'
}
}
In [7]:
grouped = df.groupby(['source','newTarget']).agg(aggregations)
grouped = grouped.rename(columns={'point':'a. point','ZL_std':'b. ZL_std',
'GA_std':'c. GA_std','Hist_std':'d. Hist_std'})
In [8]:
df.loc[:,'newTarget'].unique()
Out[8]:
In [ ]:
for h in df.loc[:,'newTarget'].unique():
df_h = grouped.xs(h,level=1).sortlevel(0,axis=1)
print(df_h)
# df_h.to_excel(writer,h)
#writer.save()
In [13]:
grouped.sortlevel(0,axis=1)
Out[13]:
In [ ]:
df.to_csv()
In [10]:
grouped.sortlevel(0,axis=1).to_csv('temp.csv',)
In [11]:
dd = pd.read_csv('temp.csv',heade)
In [12]:
dd
Out[12]:
In [14]:
dd = pd.read_csv('../output/agg_uncert/GDP2013Q1.csv')
dd.head()
Out[14]:
In [ ]: