In [251]:
leagues=['NL1','PO1']

df1=nonloans[(nonloans['toCountry']!=nonloans['fromCountry'])&(nonloans['fromLeague'].isin(leagues))] \
    .rename(columns={'fromLeague':'Origin'}).groupby(['Age','Origin','period'])['id'].count().unstack().unstack() \
    .rolling(window=1,center=False).mean().rename(columns=leagueCodeMapping)
    
df2=nonloans[(nonloans['toCountry']!=nonloans['fromCountry'])&(nonloans['toLeague'].isin(leagues))] \
    .rename(columns={'toLeague':'Destination'}).groupby(['Age','Destination','period'])['id'].count().unstack().unstack() \
    .rolling(window=1,center=False).mean().rename(columns=leagueCodeMapping)


fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(30, 16),sharex=True,sharey=True)

#df['(1995, 2000]'].plot(ax=axes[0,0], title="Age Distribution of Int'l Transfers, \nby Origin (1996-2000)", colormap='Set1', legend=False)
df1['(2000, 2005]'].plot(ax=axes[0,0], title="Age Distribution of Int'l Transfers, \nby Origin (2001-2005)", colormap='Set1', legend=True)
df1['(2005, 2010]'].plot(ax=axes[0,1], title="Age Distribution of Int'l Transfers, \nby Origin (2006-2010)", colormap='Set1', legend=True)
df1['(2010, 2015]'].plot(ax=axes[0,2], title="Age Distribution of Int'l Transfers, \nby Origin (2011-2015)", colormap='Set1', legend=True)
df2['(2000, 2005]'].plot(ax=axes[1,0], title="Age Distribution of Int'l Transfers, \nby Destination (2001-2005)", colormap='Set1', legend=True)
df2['(2005, 2010]'].plot(ax=axes[1,1], title="Age Distribution of Int'l Transfers, \nby Destination (2006-2010)", colormap='Set1', legend=True)
df2['(2010, 2015]'].plot(ax=axes[1,2], title="Age Distribution of Int'l Transfers, \nby Destination (2011-2015)", colormap='Set1', legend=True)

plt.subplots_adjust(wspace=0,hspace=.1)

fig.savefig('age_by_league.png')



In [128]:
loans[(loans['fromCountry']!=loans['toCountry'])&(loans['fromCountry'].isin(['England','Spain','Germany','Italy','France','Netherlands','Portugal','Russia','Turkey']))] \
    .rename(columns={'fromCountry':'Country'}).groupby(['Age','Country'])['id'].count().unstack() \
    .rolling(window=3,center=False).mean().plot.line(figsize=(9,6),title='Number of Foreign Loans, by Age & Loaning Country',colormap='Set1')


Out[128]:
<matplotlib.axes._subplots.AxesSubplot at 0x11a448f50>

In [12]:
loans[(loans['fromCountry']!=loans['toCountry'])&(loans['toCountry'].isin(['England','Spain','Germany','Italy','France','Netherlands','Portugal','Russia','Turkey']))] \
    .rename(columns={'toCountry':'Country'}).groupby(['Age','Country'])['id'].count().unstack() \
    .rolling(window=3,center=False).mean().plot.line(figsize=(9,6),title='Number of Foreign Loans, by Age & Receiving Country',colormap='Set1')


Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x109b77dd0>

In [11]:
nonloans[(nonloans['toCountry']!=nonloans['fromCountry'])&(nonloans['toLeague'].isin(['GB1','ES1','L1','IT1','FR1','NL1','PO1']))&(nonloans['season']>=2010)] \
    .rename(columns={'toLeague':'Destination'}).groupby(['Age','Destination'])['id'].count().unstack() \
    .rolling(window=3,center=False).mean().rename(columns=leagueCodeMapping).plot.line(figsize=(9,6),xlim=(15,45),title='Number of International Transfers, by Age & Destination')


Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x1095ae810>

In [9]:
t=transfers

fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(12, 8),sharex=True,sharey=True)

isLoan=t.join(pd.Series(np.where(t['isLoan'],'Loan','Transfer')).rename('Move Type')).groupby(['Age','Move Type','period'])['id'].count().unstack().unstack()


foreignVdomestic =t.join(pd.Series(np.where(t['fromCountry']==t['toCountry'],'Domestic','International')).rename('Move Type'))\
    .groupby(['Age','Move Type','period'])['id'].count().unstack().unstack()
    
isLoan['(2000, 2005]'].plot(ax=axes[0,0],title='2001-2005')
isLoan['(2005, 2010]'].plot(ax=axes[0,1],title='2006-2010')
isLoan['(2010, 2015]'].plot(ax=axes[0,2],title='2011-2015')

foreignVdomestic['(2000, 2005]'].plot(ax=axes[1,0])
foreignVdomestic['(2005, 2010]'].plot(ax=axes[1,1])
foreignVdomestic['(2010, 2015]'].plot(ax=axes[1,2])


plt.subplots_adjust(wspace=0,hspace=0)

fig.savefig('loan_intl.png')



In [6]:
t=transfers[transfers['season'].between(2001,2015)]

fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(15, 4),sharex=True,sharey=False)


t.groupby('Age')['id'].count().plot(ax=axes[0],title=u'# of transfers\nby age')
t.groupby('Age')['feeValue'].sum().plot(ax=axes[2], title=u'total declared transfer fees (€)\nby age')
t.groupby('Age')['mv'].sum().plot(ax=axes[1],title=u'total market value of transfers  (€)\nby age')


plt.subplots_adjust(wspace=.1,hspace=0)

fig.savefig('age_curves.png')



In [5]:
t[t['feeValue']>0].groupby('Age')


Out[5]:
<pandas.core.groupby.DataFrameGroupBy object at 0x10869d6d0>

In [4]:
t=transfers[transfers['fromCountry']!=transfers['toCountry']]

fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(5, 4),sharex=True,sharey=False)


t[t['feeValue']==0].groupby('age')['id'].count().plot(ax=axes)
t[t['feeValue']>0].groupby('age')['id'].count().plot(ax=axes)


plt.subplots_adjust(wspace=.1,hspace=0)

fig.savefig('age_curves_paid_free.png')



In [6]:
t[t['feeValue']>0]['age'].describe()


Out[6]:
count    11495.000000
mean        24.212266
std          3.630609
min         12.000000
25%         22.000000
50%         24.000000
75%         27.000000
max         39.000000
Name: age, dtype: float64

In [7]:
t[t['feeValue']>0]['age'].describe()


Out[7]:
count    11495.000000
mean        24.212266
std          3.630609
min         12.000000
25%         22.000000
50%         24.000000
75%         27.000000
max         39.000000
Name: age, dtype: float64

In [8]:
t=transfers

fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(18, 6),sharex=True,sharey=True)

g=t.groupby(['age','positionGroup','period'])['id'].count().unstack().unstack() #.plot(ax=axes)

g['(2000, 2005]'].plot(ax=axes[0],title='2001-2005')
g['(2005, 2010]'].plot(ax=axes[1],title='2006-2010')
g['(2010, 2015]'].plot(ax=axes[2],title='2011-2015')


plt.subplots_adjust(wspace=0,hspace=0)

fig.savefig('loan_intl.png')



In [32]:
nonloans[(nonloans.feeValue>0)&(nonloans.season>=2000)].groupby(['season','positionGroup'])['feeValue'].mean().unstack().plot.line(figsize=(20,10))


Out[32]:
<matplotlib.axes._subplots.AxesSubplot at 0x10c30dbd0>

In [55]:
t=nonloans
t[(t.feeValue>0)&(t.season>=2000)&(t.positionGroup.isin(['Midfield','d']))].groupby(['season'])['feeValue'].mean().rolling(window=1,center=False).mean().plot.line(figsize=(10,5))


Out[55]:
<matplotlib.axes._subplots.AxesSubplot at 0x110decc50>

In [280]:
t=nonloans
x=t[(t.toLeague.isin(leagueList))].groupby(['season','toCountry'])['feeValue'].count().unstack().rolling(window=1,center=False).mean()#.plot.line(figsize=(20,20))
y=t[(t.fromLeague.isin(leagueList))].groupby(['season','fromCountry'])['feeValue'].count().unstack().rolling(window=1,center=False).mean()#.plot.line(figsize=(20,20))
z=x.join(y,lsuffix='_import',rsuffix='_export').sort_index(axis=1)
for country in x.columns:
    z[country+'_net']=z[country+'_import']-z[country+'_export']
    z[country+'_total']=z[country+'_import']+z[country+'_export']
    
z=z.sort_index(axis=1)
zt=z.T
w=zt.reset_index()['index'].str.split('_',expand=True)
w.index=zt.index
w.columns=['country','flow']
zt=zt.join(w)
zt=zt.fillna(0).groupby(['country','flow']).sum()
zt.reset_index(level=0).groupby('country').apply(lambda x: x.ix[['import','export','net','total']]).drop('country',axis=1).unstack().to_excel('../data/output/import_export.xlsx')
ztr=zt.stack().unstack(level=0).swaplevel().reset_index().groupby(['season','flow']).apply(lambda x:x.T.drop(['season','flow']).rename(columns=lambda x:'number').sort_values('number',ascending=False).reset_index()).stack().unstack(level=[0,1,3])
ztr.to_excel('../data/output/import_export_ranked.xlsx')

In [277]:
zt.stack().unstack(level=0).swaplevel().reset_index().groupby(['season','flow']).apply(lambda x:x.T.drop(['season','flow']).rename(columns=lambda x:'number').sort_values('number',ascending=False).reset_index()).stack().unstack(level=[0,1,3])


Out[277]:
season 1992 1993 ... 2014 2015
flow export import net total export ... total export import net total
country number country number country number country number country number ... country number country number country number country number country number
0 England 10 England 23 England 13 England 33 Germany 14 ... Greece 533 Italy 213 Romania 210 Romania 35 Greece 404
1 Germany 10 Greece 17 Greece 13 Germany 23 England 10 ... Romania 501 Greece 207 Greece 197 Turkey 32 Italy 397
2 Serbia 7 Italy 16 Italy 12 Greece 21 Netherlands 8 ... Italy 351 Serbia 191 Turkey 194 Malta 26 Romania 385
3 Netherlands 6 Germany 13 Switzerland 8 Italy 20 Poland 7 ... Turkey 335 Bosnia-Herzegovina 188 Italy 184 Cyprus 19 Bosnia-Herzegovina 363
4 Poland 5 Netherlands 10 France 8 Netherlands 16 Italy 7 ... Poland 332 Romania 175 Bosnia-Herzegovina 175 Lithuania 16 Turkey 356
5 Czech Republic 5 France 10 Austria 4 Austria 12 Switzerland 6 ... England 315 Poland 167 Poland 171 Azerbaijan 15 Serbia 352
6 Austria 4 Austria 8 Netherlands 4 France 12 Austria 5 ... Cyprus 269 Turkey 162 Serbia 161 Bulgaria 12 Poland 338
7 Italy 4 Switzerland 8 Spain 3 Serbia 9 Turkey 5 ... United States 265 England 157 England 155 Kazakhstan 10 England 312
8 Greece 4 Turkey 4 Germany 3 Switzerland 8 Denmark 5 ... Germany 259 United States 152 Portugal 142 Israel 9 Portugal 282
9 Turkey 4 Spain 4 Ukraine 1 Czech Republic 8 Spain 4 ... Bosnia-Herzegovina 253 Netherlands 152 Germany 135 Belgium 7 United States 280
10 Bosnia-Herzegovina 4 Czech Republic 3 Cyprus 1 Turkey 8 Greece 4 ... Kazakhstan 251 Ukraine 143 Spain 132 Luxembourg 4 Netherlands 276
11 France 2 Croatia 2 Denmark 1 Poland 7 France 3 ... Netherlands 250 Germany 141 United States 128 Poland 4 Germany 276
12 Scotland 2 Sweden 2 Hungary 1 Spain 5 Croatia 3 ... Hungary 245 Portugal 140 Kazakhstan 127 Portugal 2 Spain 264
13 Sweden 2 Serbia 2 Portugal 0 Sweden 4 Scotland 3 ... Portugal 245 Spain 132 Netherlands 124 Finland 1 France 246
14 Croatia 2 Poland 2 Romania 0 Scotland 4 Hungary 2 ... Spain 240 France 124 Cyprus 124 Spain 0 Kazakhstan 244
15 Bulgaria 2 Scotland 2 Russia 0 Croatia 4 Czech Republic 2 ... Bulgaria 228 Slovakia 119 France 122 France -2 Ukraine 235
16 Slovenia 1 Hungary 1 Slovakia 0 Bosnia-Herzegovina 4 Serbia 2 ... Serbia 223 Kazakhstan 117 Belgium 108 Hungary -2 Cyprus 229
17 Luxembourg 1 Cyprus 1 Scotland 0 Luxembourg 2 Bulgaria 2 ... France 216 Russia 116 Malta 107 England -2 Russia 215
18 Norway 1 Denmark 1 Sweden 0 Bulgaria 2 Norway 2 ... Russia 197 Norway 109 Bulgaria 101 Germany -6 Belgium 209
19 Romania 1 Luxembourg 1 Turkey 0 Norway 2 Romania 2 ... Belgium 197 Scotland 108 Russia 99 Austria -10 Slovakia 202
20 Finland 1 Ukraine 1 Norway 0 Romania 2 Israel 1 ... Luxembourg 188 Cyprus 105 Luxembourg 93 Greece -10 Bulgaria 190
21 Spain 1 Norway 1 Lithuania 0 Finland 1 Slovenia 1 ... Ukraine 187 Czech Republic 104 Ukraine 92 Bosnia-Herzegovina -13 Malta 188
22 Slovakia 0 Romania 1 Malta 0 Denmark 1 Ukraine 1 ... Slovakia 180 Belgium 101 Finland 87 Russia -17 Scotland 185
23 Ukraine 0 Russia 0 Luxembourg 0 Cyprus 1 Sweden 0 ... Sweden 171 Slovenia 99 Hungary 83 Switzerland -22 Luxembourg 182
24 Russia 0 Slovenia 0 Azerbaijan 0 Ukraine 1 Russia 0 ... Croatia 166 Croatia 92 Slovakia 83 United States -24 Finland 173
25 Switzerland 0 Slovakia 0 Kazakhstan 0 Slovenia 1 Slovakia 0 ... Austria 154 Luxembourg 89 Azerbaijan 79 Denmark -25 Slovenia 171
26 Lithuania 0 Lithuania 0 Israel 0 Hungary 1 Lithuania 0 ... Finland 148 Bulgaria 89 Scotland 77 Slovenia -27 Norway 169
27 Portugal 0 Portugal 0 Croatia 0 Slovakia 0 Portugal 0 ... Scotland 142 Finland 86 Slovenia 72 Netherlands -28 Hungary 168
28 Malta 0 Malta 0 Belgium 0 Lithuania 0 Malta 0 ... Lithuania 142 Hungary 85 Croatia 62 Italy -29 Croatia 154
29 Azerbaijan 0 Azerbaijan 0 United States 0 Russia 0 Luxembourg 0 ... Denmark 124 Sweden 84 Norway 60 Croatia -30 Azerbaijan 143
30 Kazakhstan 0 Kazakhstan 0 Finland -1 Portugal 0 Azerbaijan 0 ... Czech Republic 122 Malta 81 Lithuania 54 Serbia -30 Czech Republic 137
31 Israel 0 Israel 0 Slovenia -1 Malta 0 Kazakhstan 0 ... Switzerland 116 Denmark 78 Denmark 53 Scotland -31 Sweden 134
32 Hungary 0 Finland 0 Czech Republic -2 Azerbaijan 0 Finland 0 ... Slovenia 115 Switzerland 68 Austria 53 Sweden -34 Denmark 131
33 Denmark 0 Bulgaria 0 Bulgaria -2 Kazakhstan 0 Cyprus 0 ... Malta 114 Azerbaijan 64 Sweden 50 Slovakia -36 Austria 116
34 Cyprus 0 Bosnia-Herzegovina 0 Poland -3 Israel 0 Bosnia-Herzegovina 0 ... Norway 108 Austria 63 Switzerland 46 Norway -49 Switzerland 114
35 Belgium 0 Belgium 0 Bosnia-Herzegovina -4 Belgium 0 Belgium 0 ... Azerbaijan 100 Lithuania 38 Israel 45 Ukraine -51 Lithuania 92
36 United States 0 United States 0 Serbia -5 United States 0 United States 0 ... Israel 50 Israel 36 Czech Republic 33 Czech Republic -71 Israel 81

37 rows × 192 columns


In [166]:
zt.reset_index(level=0)


Out[166]:
season country 1992 1993 1994 1995 1996 1997 1998 1999 2000 ... 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015
flow
export Austria 4.0 5.0 7.0 5.0 21.0 19.0 22.0 20.0 20.0 ... 80.0 61.0 80.0 81.0 70.0 65.0 67.0 60.0 85.0 63.0
import Austria 8.0 3.0 10.0 7.0 28.0 28.0 32.0 19.0 31.0 ... 74.0 87.0 82.0 68.0 64.0 58.0 59.0 61.0 69.0 53.0
net Austria 4.0 -2.0 3.0 2.0 7.0 9.0 10.0 -1.0 11.0 ... -6.0 26.0 2.0 -13.0 -6.0 -7.0 -8.0 1.0 -16.0 -10.0
total Austria 12.0 8.0 17.0 12.0 49.0 47.0 54.0 39.0 51.0 ... 154.0 148.0 162.0 149.0 134.0 123.0 126.0 121.0 154.0 116.0
export Azerbaijan 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 1.0 3.0 21.0 26.0 20.0 28.0 56.0 46.0 59.0 64.0
import Azerbaijan 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 9.0 9.0 26.0 27.0 40.0 45.0 69.0 54.0 41.0 79.0
net Azerbaijan 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 8.0 6.0 5.0 1.0 20.0 17.0 13.0 8.0 -18.0 15.0
total Azerbaijan 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 10.0 12.0 47.0 53.0 60.0 73.0 125.0 100.0 100.0 143.0
export Belgium 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 48.0 ... 170.0 130.0 141.0 106.0 99.0 109.0 93.0 98.0 96.0 101.0
import Belgium 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 51.0 ... 175.0 154.0 142.0 60.0 88.0 100.0 96.0 90.0 101.0 108.0
net Belgium 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 3.0 ... 5.0 24.0 1.0 -46.0 -11.0 -9.0 3.0 -8.0 5.0 7.0
total Belgium 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 99.0 ... 345.0 284.0 283.0 166.0 187.0 209.0 189.0 188.0 197.0 209.0
export Bosnia-Herzegovina 4.0 0.0 1.0 1.0 0.0 1.0 2.0 6.0 4.0 ... 44.0 55.0 119.0 222.0 183.0 184.0 224.0 204.0 133.0 188.0
import Bosnia-Herzegovina 0.0 0.0 0.0 0.0 1.0 2.0 1.0 2.0 4.0 ... 52.0 46.0 106.0 133.0 139.0 151.0 160.0 113.0 120.0 175.0
net Bosnia-Herzegovina -4.0 0.0 -1.0 -1.0 1.0 1.0 -1.0 -4.0 0.0 ... 8.0 -9.0 -13.0 -89.0 -44.0 -33.0 -64.0 -91.0 -13.0 -13.0
total Bosnia-Herzegovina 4.0 0.0 1.0 1.0 1.0 3.0 3.0 8.0 8.0 ... 96.0 101.0 225.0 355.0 322.0 335.0 384.0 317.0 253.0 363.0
export Bulgaria 2.0 2.0 0.0 5.0 0.0 3.0 4.0 10.0 9.0 ... 22.0 30.0 72.0 145.0 106.0 123.0 121.0 140.0 112.0 89.0
import Bulgaria 0.0 2.0 0.0 0.0 1.0 1.0 6.0 8.0 3.0 ... 16.0 32.0 83.0 107.0 113.0 124.0 144.0 146.0 116.0 101.0
net Bulgaria -2.0 0.0 0.0 -5.0 1.0 -2.0 2.0 -2.0 -6.0 ... -6.0 2.0 11.0 -38.0 7.0 1.0 23.0 6.0 4.0 12.0
total Bulgaria 2.0 4.0 0.0 5.0 1.0 4.0 10.0 18.0 12.0 ... 38.0 62.0 155.0 252.0 219.0 247.0 265.0 286.0 228.0 190.0
export Croatia 2.0 3.0 3.0 5.0 5.0 10.0 14.0 17.0 21.0 ... 98.0 89.0 104.0 121.0 147.0 215.0 140.0 94.0 93.0 92.0
import Croatia 2.0 2.0 2.0 8.0 6.0 9.0 11.0 10.0 8.0 ... 89.0 57.0 86.0 110.0 124.0 175.0 93.0 78.0 73.0 62.0
net Croatia 0.0 -1.0 -1.0 3.0 1.0 -1.0 -3.0 -7.0 -13.0 ... -9.0 -32.0 -18.0 -11.0 -23.0 -40.0 -47.0 -16.0 -20.0 -30.0
total Croatia 4.0 5.0 5.0 13.0 11.0 19.0 25.0 27.0 29.0 ... 187.0 146.0 190.0 231.0 271.0 390.0 233.0 172.0 166.0 154.0
export Cyprus 0.0 0.0 1.0 1.0 1.0 7.0 4.0 5.0 3.0 ... 59.0 86.0 86.0 131.0 156.0 120.0 101.0 122.0 122.0 105.0
import Cyprus 1.0 0.0 0.0 0.0 1.0 4.0 6.0 1.0 4.0 ... 82.0 115.0 124.0 192.0 133.0 128.0 126.0 131.0 147.0 124.0
net Cyprus 1.0 0.0 -1.0 -1.0 0.0 -3.0 2.0 -4.0 1.0 ... 23.0 29.0 38.0 61.0 -23.0 8.0 25.0 9.0 25.0 19.0
total Cyprus 1.0 0.0 1.0 1.0 2.0 11.0 10.0 6.0 7.0 ... 141.0 201.0 210.0 323.0 289.0 248.0 227.0 253.0 269.0 229.0
export Czech Republic 5.0 2.0 1.0 5.0 11.0 5.0 11.0 10.0 19.0 ... 81.0 77.0 68.0 115.0 94.0 53.0 53.0 42.0 63.0 104.0
import Czech Republic 3.0 0.0 3.0 5.0 4.0 7.0 5.0 13.0 14.0 ... 58.0 66.0 71.0 70.0 60.0 34.0 37.0 47.0 59.0 33.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
net Slovakia 0.0 0.0 1.0 0.0 0.0 -1.0 0.0 -5.0 -3.0 ... -11.0 -7.0 13.0 -39.0 -49.0 -41.0 -42.0 -17.0 -26.0 -36.0
total Slovakia 0.0 0.0 1.0 4.0 2.0 1.0 4.0 7.0 7.0 ... 75.0 77.0 135.0 207.0 171.0 115.0 112.0 121.0 180.0 202.0
export Slovenia 1.0 1.0 1.0 1.0 4.0 4.0 7.0 8.0 17.0 ... 73.0 66.0 65.0 99.0 114.0 93.0 88.0 87.0 72.0 99.0
import Slovenia 0.0 2.0 2.0 2.0 2.0 2.0 3.0 12.0 15.0 ... 57.0 43.0 34.0 80.0 77.0 52.0 53.0 45.0 43.0 72.0
net Slovenia -1.0 1.0 1.0 1.0 -2.0 -2.0 -4.0 4.0 -2.0 ... -16.0 -23.0 -31.0 -19.0 -37.0 -41.0 -35.0 -42.0 -29.0 -27.0
total Slovenia 1.0 3.0 3.0 3.0 6.0 6.0 10.0 20.0 32.0 ... 130.0 109.0 99.0 179.0 191.0 145.0 141.0 132.0 115.0 171.0
export Spain 1.0 4.0 10.0 12.0 18.0 29.0 30.0 44.0 47.0 ... 123.0 125.0 123.0 127.0 116.0 130.0 114.0 140.0 122.0 132.0
import Spain 4.0 6.0 12.0 15.0 49.0 48.0 48.0 54.0 56.0 ... 127.0 152.0 113.0 92.0 102.0 120.0 103.0 122.0 118.0 132.0
net Spain 3.0 2.0 2.0 3.0 31.0 19.0 18.0 10.0 9.0 ... 4.0 27.0 -10.0 -35.0 -14.0 -10.0 -11.0 -18.0 -4.0 0.0
total Spain 5.0 10.0 22.0 27.0 67.0 77.0 78.0 98.0 103.0 ... 250.0 277.0 236.0 219.0 218.0 250.0 217.0 262.0 240.0 264.0
export Sweden 2.0 0.0 0.0 3.0 4.0 8.0 9.0 8.0 8.0 ... 49.0 36.0 48.0 71.0 61.0 89.0 73.0 75.0 93.0 84.0
import Sweden 2.0 2.0 0.0 4.0 7.0 10.0 6.0 13.0 7.0 ... 49.0 41.0 38.0 42.0 45.0 68.0 55.0 47.0 78.0 50.0
net Sweden 0.0 2.0 0.0 1.0 3.0 2.0 -3.0 5.0 -1.0 ... 0.0 5.0 -10.0 -29.0 -16.0 -21.0 -18.0 -28.0 -15.0 -34.0
total Sweden 4.0 2.0 0.0 7.0 11.0 18.0 15.0 21.0 15.0 ... 98.0 77.0 86.0 113.0 106.0 157.0 128.0 122.0 171.0 134.0
export Switzerland 0.0 6.0 5.0 6.0 14.0 11.0 18.0 26.0 35.0 ... 75.0 64.0 50.0 55.0 56.0 67.0 52.0 61.0 56.0 68.0
import Switzerland 8.0 2.0 10.0 7.0 7.0 12.0 26.0 41.0 41.0 ... 77.0 62.0 58.0 46.0 50.0 56.0 48.0 62.0 60.0 46.0
net Switzerland 8.0 -4.0 5.0 1.0 -7.0 1.0 8.0 15.0 6.0 ... 2.0 -2.0 8.0 -9.0 -6.0 -11.0 -4.0 1.0 4.0 -22.0
total Switzerland 8.0 8.0 15.0 13.0 21.0 23.0 44.0 67.0 76.0 ... 152.0 126.0 108.0 101.0 106.0 123.0 100.0 123.0 116.0 114.0
export Turkey 4.0 5.0 1.0 8.0 8.0 17.0 17.0 17.0 40.0 ... 121.0 127.0 148.0 156.0 157.0 155.0 145.0 158.0 166.0 162.0
import Turkey 4.0 11.0 9.0 13.0 18.0 19.0 28.0 29.0 64.0 ... 146.0 152.0 186.0 180.0 186.0 179.0 197.0 210.0 169.0 194.0
net Turkey 0.0 6.0 8.0 5.0 10.0 2.0 11.0 12.0 24.0 ... 25.0 25.0 38.0 24.0 29.0 24.0 52.0 52.0 3.0 32.0
total Turkey 8.0 16.0 10.0 21.0 26.0 36.0 45.0 46.0 104.0 ... 267.0 279.0 334.0 336.0 343.0 334.0 342.0 368.0 335.0 356.0
export Ukraine 0.0 1.0 1.0 5.0 7.0 10.0 9.0 11.0 12.0 ... 66.0 96.0 100.0 91.0 92.0 85.0 86.0 108.0 113.0 143.0
import Ukraine 1.0 3.0 2.0 4.0 12.0 14.0 8.0 10.0 18.0 ... 71.0 102.0 99.0 99.0 115.0 95.0 78.0 86.0 74.0 92.0
net Ukraine 1.0 2.0 1.0 -1.0 5.0 4.0 -1.0 -1.0 6.0 ... 5.0 6.0 -1.0 8.0 23.0 10.0 -8.0 -22.0 -39.0 -51.0
total Ukraine 1.0 4.0 3.0 9.0 19.0 24.0 17.0 21.0 30.0 ... 137.0 198.0 199.0 190.0 207.0 180.0 164.0 194.0 187.0 235.0
export United States 0.0 0.0 0.0 0.0 4.0 9.0 6.0 12.0 22.0 ... 123.0 131.0 100.0 77.0 114.0 120.0 138.0 96.0 102.0 152.0
import United States 0.0 0.0 0.0 17.0 11.0 18.0 17.0 23.0 35.0 ... 148.0 151.0 132.0 131.0 191.0 189.0 202.0 160.0 163.0 128.0
net United States 0.0 0.0 0.0 0.0 7.0 9.0 11.0 11.0 13.0 ... 25.0 20.0 32.0 54.0 77.0 69.0 64.0 64.0 61.0 -24.0
total United States 0.0 0.0 0.0 0.0 15.0 27.0 23.0 35.0 57.0 ... 271.0 282.0 232.0 208.0 305.0 309.0 340.0 256.0 265.0 280.0

148 rows × 25 columns


In [140]:
z.T.index


Out[140]:
Index([u'Austria_export', u'Austria_import', u'Austria_net', u'Austria_total',
       u'Azerbaijan_export', u'Azerbaijan_import', u'Azerbaijan_net',
       u'Azerbaijan_total', u'Belgium_export', u'Belgium_import',
       ...
       u'Turkey_net', u'Turkey_total', u'Ukraine_export', u'Ukraine_import',
       u'Ukraine_net', u'Ukraine_total', u'United States_export',
       u'United States_import', u'United States_net', u'United States_total'],
      dtype='object', length=148)

In [121]:



Out[121]:
toCountry toLeague

In [1]:
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
from urllib2 import urlopen, Request
from bs4 import BeautifulSoup
from pandas import DataFrame
import pandas as pd
import numpy as np
import re
import os.path 
import datetime 
import math
import matplotlib.pyplot as plt

transfers = pd.read_csv('../data/merged/transfers.csv')
loans = pd.read_csv('../data/merged/loans.csv')
nonloans = pd.read_csv('../data/merged/nonloans.csv')
players=pd.read_csv('../data/merged/players.csv')

leagueCodeMapping = {'GB1':'Premier League (England)','FR1':'Ligue 1 (France)',
                                                         'ES1':'La Liga (Spain)','IT1':'Serie A (Italy)','L1':'Bundesliga (Germany)',
                                                         'PO1':'Primeira Liga (Portugal)','NL1':'Eredivisie (Netherlands)'}

teamIdMap = pd.concat([transfers[['toTeamId','toTeamName','season']].rename(columns={'toTeamId':'teamId','toTeamName':'teamName'}),
    transfers[['fromTeamId','fromTeamName','season']].rename(columns={'fromTeamId':'teamId','fromTeamName':'teamName'})],ignore_index=True) \
    .sort_values('season',ascending=False).drop_duplicates('teamId').set_index('teamId')['teamName'].to_dict()
    
agentIdMap = transfers[['playersAgentId','playersAgent']].sort_values('playersAgent',ascending=False).drop_duplicates('playersAgentId').set_index('playersAgentId')['playersAgent'].to_dict()

leagueList = ['GB1','ES1','L1','IT1','FR1','PO1','NL1','TR1','RU1','BE1','MLS1','UKR1','GR1','RO1','ZYP1','KR1','SER1','BOS1','BU1','DK1','SE1','NO1','LI1','SC1','ISR1','PL1','UNG1','A1','C1','MAL1','KAS1','TS1','SLO1','SL1','FI1','LUX1','AZ1']


/Users/sunkevin/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2871: DtypeWarning: Columns (40,45,47,49,51,52) have mixed types. Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)
/Users/sunkevin/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2871: DtypeWarning: Columns (45,47) have mixed types. Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)
/Users/sunkevin/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2871: DtypeWarning: Columns (45,47,49,52) have mixed types. Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)
/Users/sunkevin/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2871: DtypeWarning: Columns (32,34) have mixed types. Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)