In [1]:
import pandas as pd
In [2]:
%pylab inline
In [3]:
df = pd.read_csv('data/eu_trade_sums.csv')
In [4]:
df.head()
Out[4]:
In [5]:
df.dtypes
Out[5]:
In [79]:
df.std()
Out[79]:
In [80]:
yrs = [str(yr) for yr in range(2002,2016)]
In [6]:
df = df.set_index('geo')
In [26]:
df[(df['trade_type'] == 'Export') &
(df['partner'] == 'EU28')].loc[['EU28', 'UK']][yrs].T.plot()
Out[26]:
In [29]:
df[(df['trade_type'] == 'Import') &
(df['partner'] == 'EU28')].loc[['EU28', 'UK']][yrs].T.plot()
Out[29]:
In [30]:
df[(df['trade_type'] == 'Import') &
(df['partner'] == 'EXT_EU28')].loc[['EU28', 'UK']][yrs].T.plot()
Out[30]:
In [33]:
df[(df['trade_type'] == 'Export') &
(df['partner'] == 'EXT_EU28')].loc[['EU28', 'UK']][yrs].T.plot()
Out[33]:
In [34]:
export_df = df[(df['trade_type'] == 'Export') & (df['partner'] == 'EXT_EU28')].loc[['EU28', 'UK']][yrs].T
In [37]:
export_df = export_df.rename(columns={'EU28':'EU28_TO_EXT', 'UK': 'UK_TO_EXT'})
In [42]:
export_df = pd.concat([export_df, df[(df['trade_type'] == 'Export') &
(df['partner'] == 'EU28')].loc[['EU28', 'UK']][yrs].T], axis=1)
In [43]:
export_df = export_df.rename(columns={'EU28':'EU28_TO_INT', 'UK': 'UK_TO_INT'})
In [44]:
export_df.plot()
Out[44]:
In [74]:
export_df[['UK_TO_EXT', 'UK_TO_INT']].plot()
Out[74]:
In [87]:
df.head()
Out[87]:
In [91]:
pct_change_df = df.copy()
In [92]:
for yr in yrs:
pct_change_df[yr] = (df[yr] - df[str(int(yr)-1)]) / df[str(int(yr)-1)]
In [105]:
df = df[~df.index.isin(['EU28'])]
In [95]:
pct_change_df.head()
Out[95]:
In [96]:
for yr in yrs:
print(yr, pct_change_df[yr].max() - pct_change_df[yr].min())
In [97]:
pct_change_df['2010'].mean()
Out[97]:
In [98]:
pct_change_df['2010'].std()
Out[98]:
In [99]:
pct_change_df[pct_change_df['2010'].abs() >= (pct_change_df['2010'].mean() + 2*pct_change_df['2010'].std())]
Out[99]:
In [100]:
pct_change_df['2010'].sort_values()
Out[100]:
In [101]:
pct_change_df[pct_change_df['2010'] < 0]
Out[101]:
In [102]:
pct_change_df[pct_change_df['2010'] > .4]
Out[102]:
In [103]:
pct_change_df.loc[['LT', 'LU']]
Out[103]:
In [ ]: