In [3]:
#number of transfers from individual clubs  - first time a player changes countries
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['season'].between(1995,2015))&(~transfers['fromTeamId'].isin([75,123,515,2113,2077]))].drop_duplicates(subset=['id'],keep='last').groupby(['fromTeamName','fromTeamId'])['id'].count().sort_values(ascending=False)[:40].plot.bar(figsize=(20,5))


Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x107fa6210>

In [4]:
#number of transfers from individual clubs  - any time a player changes countries
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['season'].between(1995,2015))&(~transfers['fromTeamId'].isin([75,123,515,2113,2077]))].groupby(['fromTeamName','fromTeamId'])['id'].count().sort_values(ascending=False)[:40].plot.bar(figsize=(20,5))


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x1074632d0>

In [5]:
#total documented fees paid for transfers from individual clubs  - any time a player changes countries
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['season'].between(1995,2015))&(~transfers['fromTeamId'].isin([75,123,515,2113,2077]))].groupby(['fromTeamName','fromTeamId'])['feeValue'].sum().sort_values(ascending=False)[:40].plot.bar(figsize=(20,5))


Out[5]:
<matplotlib.axes._subplots.AxesSubplot at 0x109fcc590>

In [9]:
#total documented fees paid for transfers from individual clubs  - first time a player changes countries
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['season'].between(0,2015))].drop_duplicates(subset=['id'],keep='last').groupby(['fromTeamName','fromTeamId'])['feeValue'].sum().sort_values(ascending=False)[:40].plot.bar(figsize=(20,5))


Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x10b7a34d0>

In [17]:
#number of transfers from each league to GB1 (English Premier) - first transfer to league only
transfers[((transfers['toLeague'] != transfers['fromLeague']))&(transfers['toLeague'] == 'GB1')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('fromLeague')['id'].count().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[17]:
<matplotlib.axes._subplots.AxesSubplot at 0x10b93df10>

In [16]:
#total documented fees paid for transfers from each league to GB1 (English Premier) - first transfer to league only
transfers[((transfers['toLeague'] != transfers['fromLeague']))&(transfers['toLeague'] == 'GB1')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('fromLeague')['feeValue'].sum().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x10bd96e50>

In [19]:
#total documented fees paid for transfers from each league to PO1 (Portuguese Top Tier) - first transfer to league only
transfers[((transfers['toLeague'] != transfers['fromLeague']))&(transfers['toLeague'] == 'PO1')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('fromLeague')['feeValue'].sum().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x10dec0b50>

In [54]:
#number transfers to each league from PO1 (Portuguese Top Tier) - first transfer from league only
transfers[((transfers['toLeague'] != transfers['fromLeague']))&(transfers['fromLeague'] == 'PO1')&(transfers['season'].between(2000,2015))].drop_duplicates(subset=['id'],keep='last').groupby('toLeague')['id'].count().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[54]:
<matplotlib.axes._subplots.AxesSubplot at 0x11cbc8f10>

In [53]:
#total documented fees paid for transfers to each league from PO1 (Portuguese Top Tier) - first transfer from league only
transfers[((transfers['toLeague'] != transfers['fromLeague']))&(transfers['fromLeague'] == 'PO1')&(transfers['season'].between(2000,2015))].drop_duplicates(subset=['id'],keep='last').groupby('toLeague')['feeValue'].sum().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[53]:
<matplotlib.axes._subplots.AxesSubplot at 0x11be05690>

In [21]:
#total documented fees paid for transfers from each league to NL1 (Dutch Top Tier) - first transfer to league only
transfers[((transfers['toLeague'] != transfers['fromLeague']))&(transfers['toLeague'] == 'NL1')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('fromLeague')['feeValue'].sum().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0x10dff1250>

In [79]:
#total number of international transfers from each league to TR1 (Turkish top tier) - first transfer to league only
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['toLeague'] == 'TR1')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('fromLeague')['id'].count().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[79]:
<matplotlib.axes._subplots.AxesSubplot at 0x1235b8610>

In [77]:
#total documented fees paid for transfers from each league to TR1 (Turkish Top Tier) - first transfer to league only
transfers[((transfers['toLeague'] != transfers['fromLeague']))&(transfers['toLeague'] == 'TR1')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('fromLeague')['feeValue'].sum().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[77]:
<matplotlib.axes._subplots.AxesSubplot at 0x1225b4710>

In [81]:
#total number of international transfers from each league to RU1 (Russian top tier) - first transfer to league only
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['toLeague'] == 'RU1')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('fromLeague')['id'].count().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[81]:
<matplotlib.axes._subplots.AxesSubplot at 0x123ed47d0>

In [91]:
#total documented fees paid for transfers from each league to RU1 (Russian Top Tier) - first transfer to league only
transfers[((transfers['toLeague'] != transfers['fromLeague']))&(transfers['toLeague'] == 'RU1')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('fromLeague')['feeValue'].sum().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[91]:
<matplotlib.axes._subplots.AxesSubplot at 0x11bf1bcd0>

In [70]:
transfers[((transfers['fromCountry'] != transfers['toCountry']))&(transfers['fromCountry']=='Italy')].drop_duplicates(subset=['id'],keep='last').rename(columns={'toCountry':'destination'}).groupby('destination')['id'].count().sort_values()


Out[70]:
destination
Latvia                   1
Trinidad and Tobago      1
South Africa             1
Puerto Rico              1
Montenegro               1
Lithuania                1
Liechtenstein            1
Kazakhstan               1
Iran                     1
Georgia                  1
Gabon                    1
Estonia                  1
Egypt                    1
Ecuador                  1
Vietnam                  1
Costa Rica               1
Bolivia                  1
Canada                   1
Tunisia                  2
Israel                   2
Colombia                 2
Azerbaijan               2
India                    2
Qatar                    2
Cyprus                   3
Peru                     3
Saudi Arabia             3
Finland                  3
Australia                3
Venezuela                3
                      ... 
Chile                   10
Czech Republic          11
Hungary                 11
Austria                 11
Scotland                12
Denmark                 12
Norway                  12
Poland                  12
Mexico                  13
Sweden                  13
Bulgaria                14
Croatia                 17
United States           18
Uruguay                 21
Russia                  21
San Marino              24
Turkey                  26
Netherlands             31
Slovenia                35
Romania                 51
Greece                  54
Belgium                 61
Brazil                  61
Germany                 64
Portugal                65
Switzerland             75
Argentina               75
France                  89
Spain                  181
England                182
Name: id, dtype: int64

In [21]:
p=transfers[((transfers['fromCountry'] != transfers['toCountry']))].drop_duplicates(subset=['id'],keep='last')
topdestinations=p.groupby('toCountry')['id'].count().sort_values(ascending=False)
toporigins=p.groupby('fromCountry')['id'].count().sort_values(ascending=False)

print toporigins[toporigins>100].index.tolist()
print topdestinations[topdestinations>100].index.tolist()


['France', 'Brazil', 'Serbia', 'Spain', 'Germany', 'Italy', 'Netherlands', 'England', 'Croatia', 'Bosnia-Herzegovina', 'Romania', 'Belgium', 'Portugal', 'Ukraine', 'Greece', 'United States', 'Argentina', 'Sweden', 'Turkey', 'Denmark', 'Russia', 'Norway', 'Bulgaria', 'Lithuania', 'Uruguay', 'Switzerland', 'Poland', 'Czech Republic', 'Cyprus', 'Slovenia', 'Nigeria', 'Ghana', 'Slovakia', 'Austria', 'Colombia', 'Scotland', 'Hungary', 'Cameroon', 'Finland', 'Montenegro', 'Macedonia', 'Iceland', 'Georgia', 'Australia', "Cote d'Ivoire", 'Belarus', 'Senegal']
['England', 'Italy', 'Germany', 'Belgium', 'Portugal', 'Spain', 'Greece', 'Turkey', 'Netherlands', 'France', 'Russia', 'Cyprus', 'Norway', 'Romania', 'United States', 'Ukraine', 'Sweden', 'Bosnia-Herzegovina', 'Croatia', 'Scotland', 'Switzerland', 'Austria', 'Serbia', 'Bulgaria', 'Denmark', 'Poland', 'Lithuania', 'Hungary', 'Slovenia', 'Czech Republic', 'Israel', 'Moldova', 'Belarus', 'Montenegro', 'Mexico', 'Brazil', 'Kazakhstan', 'Argentina', 'Finland']

In [22]:
def makeDestinationChart(country):
    fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15,5),sharex=False,sharey=False)
    p=nonloans[((nonloans['fromCountry'] != nonloans['toCountry']))]#.drop_duplicates(subset=['id'],keep='last')
    q=p[p['fromCountry']==country].rename(columns={'toCountry':'destination'})
    r1=q[q['feeValue']==0].groupby('destination')['id'].count().sort_values().rename(columns={'toCountry':'destination'})[-10:]
    r2=q[q['feeValue']>0].groupby('destination')['id'].count().sort_values(ascending=False).rename(columns={'toCountry':'destination'})[:10].sort_values()
    r1.plot.barh(ax=axes[0],title='# of free int\'l transfers, from '+country+' to...')
    r2.plot.barh(ax=axes[1],title='# of paid int\'l transfers, from '+country+' to...')
    fig.savefig('../images/from_'+country+'.png')

for country in toporigins[toporigins>100].index.tolist():
    makeDestinationChart(country)


/Users/sunkevin/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py:424: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

In [23]:
def makeSourceChart(country):
    fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15,5),sharex=False,sharey=False)
    p=nonloans[((nonloans['fromCountry'] != nonloans['toCountry']))]#.drop_duplicates(subset=['id'],keep='last')
    q=p[p['toCountry']==country].rename(columns={'fromCountry':'origin'})
    r1=q[q['feeValue']==0].groupby('origin')['id'].count().sort_values()[-10:]
    r2=q[q['feeValue']>0].groupby('origin')['id'].count().sort_values(ascending=False)[:10].sort_values()
    r1.plot.barh(ax=axes[0],title='# of free int\'l transfers, to '+country + ' from...')
    r2.plot.barh(ax=axes[1],title='# of paid int\'l transfers, to '+country + ' from...')
    fig.savefig('../images/to_'+country+'.png')
    
for country in topdestinations[topdestinations>100].index.tolist():
    makeSourceChart(country)



In [11]:
nonloans[(nonloans['fromCountry']=='Portugal')&(nonloans['toCountry']=='Cyprus')].sort_values('mv',ascending=False)


Out[11]:
id playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... Outfitter Shoe model Shoe size day of death facebook instagram twitter website feeValue isLoan
91335 14327 Luís Loureiro 2007-08-01 2007 Portugal PO1 336.0 Sporting CP Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
99327 150568 Valentín Viola 2016-01-15 2015 Portugal PO2 10949.0 Sporting B Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
96201 77750 Maykon 2012-07-01 2012 Portugal Other Portugal 2639.0 Leiria Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
90394 13974 Wender 2009-08-01 2009 Portugal PO1 1075.0 Braga Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
6611 3625 Jardel 2007-01-01 2006 Portugal PO1 1436.0 Beira-Mar Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92411 18856 João Alves 2012-07-01 2012 Portugal PO1 2420.0 Vit. Guimarães Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
94809 27369 João Guilherme 2013-07-01 2013 Portugal PO1 1301.0 Marítimo Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
84577 14110 João Paulo 2012-07-18 2012 Portugal PO1 2420.0 Vit. Guimarães Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
6221 3981 Silas 2011-01-01 2010 Portugal PO1 2639.0 Leiria Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
94947 27434 Evandro Roncatto 2010-01-01 2009 Portugal PO1 2995.0 Paços Ferreira Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
91082 14282 Danielson 2012-07-01 2012 Portugal PO1 982.0 Nacional Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
88188 14123 Kenedy 2005-07-01 2005 Portugal PO1 2990.0 Coimbra Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92006 34024 Tiago Targino 2013-07-01 2013 Portugal PO1 4750.0 Olhanense Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
23272 14121 Chaínho 2007-08-01 2007 Portugal PO1 982.0 Nacional Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92821 33734 Edson Nobre 2009-07-01 2009 Portugal PO1 2995.0 Paços Ferreira Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
89764 13199 Davide Dias 2011-07-01 2011 Portugal PO2 4814.0 Naval Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
97274 55253 Diego Barcelos 2014-07-01 2014 Portugal PO1 982.0 Nacional Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92845 25394 Márcio Paiva 2009-07-01 2009 Portugal PO1 2425.0 Rio Ave FC Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92827 33830 Janicio Martins 2009-07-01 2009 Portugal PO1 1085.0 Vitória Setúbal Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92856 37539 Zé Carlos 2007-07-01 2007 Portugal PO1 1075.0 Braga Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
94999 52028 Gabriel Gómez 2010-07-01 2010 Portugal PO2 2457.0 Belenenses Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
88732 14336 Miguelito 2012-07-01 2012 Portugal PO1 1085.0 Vitória Setúbal Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
96066 33647 Philip Chidi 2010-07-01 2010 Portugal PO1 2425.0 Rio Ave FC Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
33476 12148 Selim Benachour 2012-07-01 2012 Portugal PO1 1301.0 Marítimo Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN https://www.benachour18.com 0.0 False
88927 14370 Rui Dolores 2007-07-01 2007 Portugal Other Portugal 6318.0 Santa Maria da Feira Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92986 34029 Hélder Cabral 2013-07-01 2013 Portugal PO1 2990.0 Coimbra Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
92320 31109 Vítor Vinha 2009-08-01 2009 Portugal PO1 2990.0 Coimbra Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
88515 22448 Elias 2011-07-01 2011 Portugal PO2 7378.0 Portimonense Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
90415 13976 Paulo Jorge 2009-07-01 2009 Portugal PO1 1075.0 Braga Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
89734 17292 Joeano 2009-07-01 2009 Portugal PO1 1085.0 Vitória Setúbal Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
91440 34828 Moses Sakyi 2008-01-01 2007 Portugal PO1 2431.0 Estrela Amadora Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
89060 14386 Vitor Pereira 2008-07-01 2008 Portugal Other Portugal 7117.0 Bragança Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
93756 24707 Sufrim 2008-07-01 2008 Portugal Other Portugal 3352.0 Louletano Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
89239 24832 João Paiva 2005-07-01 2005 Portugal Other Portugal 3265.0 Espinho Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN https://www.joaopaiva.ch NaN False
91932 37577 Paulinho 2007-07-01 2007 Portugal Other Portugal 10787.0 Marítimo B Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
88981 14376 Tiago Carneiro 2006-07-01 2006 Portugal Other Portugal 3271.0 Maia Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
92522 17365 Puma 2006-07-01 2006 Portugal Other Portugal 3271.0 Maia Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
91544 22556 Edgar Marcelino 2007-01-01 2006 Portugal PO2 2420.0 Vit. Guimarães Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
88753 14338 Pedro Moita 2005-07-01 2005 Portugal Other Portugal 6023.0 Sanjoanense Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
91577 14371 Rui Figueiredo 2007-07-01 2007 Portugal PO2 3336.0 Desportivo Aves Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
89705 13193 Tiago Lemos 2007-07-01 2007 Portugal Other Portugal 3352.0 Louletano Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
90198 13885 Ernesto 2008-07-01 2008 Portugal PO2 1465.0 Estoril Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
89281 16772 José Nando 2005-07-01 2005 Portugal PO1 2420.0 Vit. Guimarães Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
91253 14316 Júnior 2007-07-01 2007 Portugal Other Portugal 5227.0 Atlético Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
89145 14395 Ivo Afonso 2006-07-01 2006 Portugal Other Portugal 979.0 Moreirense Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
89036 14383 Vargas 2006-07-01 2006 Portugal PO2 1465.0 Estoril Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
91232 14314 Junas 2006-07-01 2006 Portugal Other Portugal 979.0 Moreirense Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
23372 58262 Bakero 2008-07-01 2008 Portugal Other Portugal 3327.0 Penafiel Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
71131 59791 Jorge Teixeira 2008-07-01 2008 Portugal Other Portugal 6987.0 Fátima Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
90095 13830 Santamaria 2010-08-01 2010 Portugal Other Portugal 6986.0 Pinhalnovense Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
90672 12090 Nordin Wooter 2004-07-01 2004 Portugal PO1 1075.0 Braga Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92426 22442 Luís Torres 2009-07-01 2009 Portugal Other Portugal 5227.0 Atlético Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92773 82458 Tiquinho 2007-07-01 2007 Portugal PO1 1301.0 Marítimo Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
93119 133174 Ricardo Catchana 2011-07-01 2011 Portugal Other Portugal 7056.0 Mafra Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
93928 35660 Hernâni Borges 2007-07-01 2007 Portugal PO2 3336.0 Desportivo Aves Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
93981 123740 Todor Kutchoukov 2007-07-01 2007 Portugal PO2 1436.0 Beira-Mar Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
95196 226886 Ikechukwu Obi 2008-07-01 2008 Portugal PO2 2503.0 Boavista Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
98215 25513 Hugo Machado 2006-07-01 2006 Portugal Other Portugal 5707.0 Barreirense Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
100858 257139 Leandro Souza 2013-07-01 2013 Portugal Other Portugal 10005.0 Mirandela Cyprus ZYP1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
130870 133450 Dossa Júnior 2006-07-01 2006 Portugal Other Portugal 3332.0 Imortal Cyprus Other Cyprus ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False

145 rows × 56 columns


In [29]:
nonloans[(nonloans['fromCountry']=='Portugal')&(nonloans['toCountry']=='Romania')&(nonloans['Nationality']!='Romania')].sort_values('feeValue',ascending=False)


Out[29]:
id playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... Outfitter Shoe model Shoe size day of death facebook instagram twitter website feeValue isLoan
28796 22560 Wesley 2009-02-01 2008 Portugal PO1 3345.0 Leixões Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 1500000.0 False
93684 16106 Spadacio 2008-07-01 2008 Portugal PO1 982.0 Nacional Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 1500000.0 False
91195 14309 João Paulo 2008-01-01 2007 Portugal PO1 2639.0 Leiria Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 1200000.0 False
90406 13975 Éder Bonfim 2008-07-01 2008 Portugal PO2 2639.0 Leiria Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 1000000.0 False
90977 14262 Amoreirinha 2007-07-01 2007 Portugal PO1 294.0 Benfica Romania RO1 ... NaN NaN NaN NaN https://www.facebook.com/daniel.amoreirinha?fr... NaN NaN NaN 1000000.0 False
93874 34953 Cássio 2010-07-01 2010 Portugal PO1 2639.0 Leiria Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 900000.0 False
138616 36070 Sreten Sretenovic 2008-07-01 2008 Portugal PO1 294.0 Benfica Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 800000.0 False
92364 22945 Césinha 2007-07-01 2007 Portugal PO1 1075.0 Braga Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 800000.0 False
91028 14274 Cadú 2006-07-01 2006 Portugal PO1 2503.0 Boavista Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 750000.0 False
96945 76090 Cauê 2012-07-01 2012 Portugal PO1 4750.0 Olhanense Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 700000.0 False
92787 24733 Didi 2007-01-01 2006 Portugal PO1 2995.0 Paços Ferreira Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN https://www.didisports.com.br 700000.0 False
88900 14365 Ricardo Fernandes 2008-07-01 2008 Portugal PO1 982.0 Nacional Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 500000.0 False
93458 41616 Mourtala Diakité 2008-07-01 2008 Portugal PO2 2503.0 Boavista Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 500000.0 False
84580 14110 João Paulo 2008-07-01 2008 Portugal PO1 720.0 FC Porto Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 500000.0 False
93882 41786 André Leão 2007-07-01 2007 Portugal PO2 1436.0 Beira-Mar Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 500000.0 False
92194 14149 Cláudio Pitbull 2008-07-01 2008 Portugal PO1 720.0 FC Porto Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 500000.0 False
79496 6973 Ousmane N'Doye 2008-02-01 2007 Portugal PO1 2990.0 Coimbra Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 500000.0 False
91663 59000 Mário Felgueiras 2012-07-01 2012 Portugal PO1 1075.0 Braga Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 500000.0 False
89482 13122 Manuel José 2006-07-01 2006 Portugal PO1 2503.0 Boavista Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 500000.0 False
97979 156005 Eduardo Jumisse 2012-07-01 2012 Portugal PO2 3345.0 Leixões Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 400000.0 False
92372 22434 Rui Duarte 2008-07-01 2008 Portugal PO1 2431.0 Estrela Amadora Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 400000.0 False
90143 13871 Paulo Adriano 2007-07-01 2007 Portugal PO1 2420.0 Vit. Guimarães Romania Other Romania ... NaN NaN NaN NaN NaN NaN NaN NaN 400000.0 False
91412 18947 Carlos Milhazes 2008-07-01 2008 Portugal PO1 2425.0 Rio Ave FC Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 350000.0 False
95137 56727 Cardoso 2008-01-01 2007 Portugal PO1 2431.0 Estrela Amadora Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 350000.0 False
92512 17362 Hugo Alcântara 2008-07-01 2008 Portugal PO1 2457.0 Belenenses Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 300000.0 False
86571 33831 Modou Sougou 2011-07-01 2011 Portugal PO1 2990.0 Coimbra Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 300000.0 False
91401 48642 Jorge Tavares 2008-07-01 2008 Portugal Other Portugal 3341.0 Olivais Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 250000.0 False
90689 14140 Ezequias 2008-07-01 2008 Portugal PO1 720.0 FC Porto Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 250000.0 False
94344 36044 Milos Pavlovic 2009-01-01 2008 Portugal PO1 2990.0 Coimbra Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 250000.0 False
93300 24175 Pedro Taborda 2008-07-01 2008 Portugal PO1 4814.0 Naval Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 250000.0 False
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
91813 23211 Carlos 2006-01-01 2005 Portugal PO1 2503.0 Boavista Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
91922 37577 Paulinho 2016-01-07 2015 Portugal Other Portugal 16222.0 Limianos Romania Other Romania ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
91995 23270 Diogo Valente 2012-07-01 2012 Portugal PO1 2990.0 Coimbra Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92112 24847 Pedro Oliveira 2006-07-01 2006 Portugal PO1 1085.0 Vitória Setúbal Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92165 24883 Miguel Tininho 2009-07-01 2009 Portugal PO1 2457.0 Belenenses Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
90224 9814 Bruno Moraes 2010-09-01 2010 Portugal PO1 720.0 FC Porto Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN https://www.moraessoccer.com 0.0 False
92361 22945 Césinha 2012-10-25 2012 Portugal PO1 979.0 Moreirense Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
90013 63362 Ibraima Baldé 2009-08-01 2009 Portugal PO2 1436.0 Beira-Mar Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
53363 14334 Marcos António 2010-07-01 2010 Portugal PO2 2457.0 Belenenses Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
92714 39689 João Coimbra 2015-01-16 2014 Portugal PO2 7788.0 Académico Viseu Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
89799 13207 António Semedo 2006-07-01 2006 Portugal PO1 2431.0 Estrela Amadora Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
93508 44698 Camora 2011-07-01 2011 Portugal PO2 4814.0 Naval Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
93612 34009 José Williams 2010-07-01 2010 Portugal PO2 3348.0 Trofense Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
88771 14344 Nuno Claro 2007-07-01 2007 Portugal PO1 2995.0 Paços Ferreira Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
94147 25509 Diogo Fonseca 2013-07-01 2013 Portugal PO2 7179.0 Tondela Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
94593 57962 Ivan Santos 2016-03-15 2015 Portugal PO2 2421.0 Freamunde Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
153727 187908 Hugo Sousa 2011-07-01 2011 Portugal Other Portugal 9844.0 FC Porto U19 Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN 0.0 False
71754 52999 Renan 2011-07-01 2011 Portugal PO1 2420.0 Vit. Guimarães Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
90015 63362 Ibraima Baldé 2008-07-01 2008 Portugal Other Portugal 4535.0 Odivelas Romania Other Romania ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
90239 13951 Lourenço 2013-08-03 2013 Portugal PO2 4294.0 Farense Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
90885 14239 Mário Carlos 2006-01-01 2005 Portugal PO2 5707.0 Barreirense Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
93298 24175 Pedro Taborda 2012-07-01 2012 Portugal PO2 4814.0 Naval Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
93827 44167 Ademar 2008-07-01 2008 Portugal PO1 2425.0 Rio Ave FC Romania Other Romania ... NaN NaN NaN NaN NaN NaN NaN https://www.ademarxavier.webs.com NaN False
94987 45371 Celestino 2011-12-01 2011 Portugal PO2 2457.0 Belenenses Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
95465 95267 Pedro Queirós 2007-07-01 2007 Portugal Other Portugal 8351.0 T. Moncorvo Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
96051 75116 Lionn 2011-07-01 2011 Portugal PO1 2420.0 Vit. Guimarães Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
97690 62634 Hélder Castro 2010-07-01 2010 Portugal PO2 3349.0 Feirense Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
98132 74200 Jaime Simões 2014-07-01 2014 Portugal PO2 1436.0 Beira-Mar Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
98290 42960 Tiago Costa 2010-01-01 2009 Portugal Other Portugal 6912.0 Vizela Romania RO1 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False
100080 213048 Tin Karamatic 2014-01-01 2013 Portugal PO1 4750.0 Olhanense Romania Other Romania ... NaN NaN NaN NaN NaN NaN NaN NaN NaN False

93 rows × 56 columns


In [ ]:


In [55]:
#total documented fees paid for transfers to each league from BE1 (Belgian Top Tier) - first transfer from league only
transfers[((transfers['toLeague'] != transfers['fromLeague']))&(transfers['fromLeague'] == 'BE1')&(transfers['season'].between(2000,2015))].drop_duplicates(subset=['id'],keep='last').groupby('toLeague')['feeValue'].sum().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


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

In [63]:
#total number of transfers to each league from Brazil - first transfer from country only
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['fromCountry'] == 'Brazil')&(transfers['season'].between(2000,2010))].drop_duplicates(subset=['id'],keep='last').groupby('toLeague')['id'].count().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[63]:
<matplotlib.axes._subplots.AxesSubplot at 0x11e5d0310>

In [60]:
#total documented fees paid for transfers to each league from Brazil - first transfer from country only
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['fromCountry'] == 'Brazil')&(transfers['season'].between(2000,2010))].drop_duplicates(subset=['id'],keep='last').groupby('toLeague')['feeValue'].sum().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[60]:
<matplotlib.axes._subplots.AxesSubplot at 0x11d86c690>

In [62]:
#total number of transfers to each league from Argentina - first transfer from country only
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['fromCountry'] == 'Argentina')&(transfers['season'].between(2000,2010))].drop_duplicates(subset=['id'],keep='last').groupby('toLeague')['id'].count().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[62]:
<matplotlib.axes._subplots.AxesSubplot at 0x11e588310>

In [65]:
#total documented fees paid for transfers to each league from Nigeria - first transfer from country only
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['fromCountry'] == 'Argentina')&(transfers['season'].between(2000,2010))].drop_duplicates(subset=['id'],keep='last').groupby('toLeague')['feeValue'].sum().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[65]:
<matplotlib.axes._subplots.AxesSubplot at 0x11f8eaad0>

In [19]:
#total number of transfers to each league from Mexico - first transfer from country only
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['fromCountry'] == 'Mexico')&(transfers['season'].between(1995,2015))].drop_duplicates(subset=['id'],keep='last').groupby('toLeague')['id'].count().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x10d81f410>

In [76]:
#total documented fees paid for transfers to each league from Mexico - first transfer from country only
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['fromCountry'] == 'Mexico')&(transfers['season'].between(1995,2015))].drop_duplicates(subset=['id'],keep='last').groupby('toLeague')['feeValue'].sum().sort_values(ascending=False)[:20].plot.bar(figsize=(20,5))


Out[76]:
<matplotlib.axes._subplots.AxesSubplot at 0x121fb5ad0>

In [16]:
#total documented fees paid for transfers from each league to NL1 (Dutch Top Tier) - first transfer to league only
transfers[((transfers['toLeague'] != transfers['fromLeague']))&(transfers['toLeague'] == 'NL1')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('fromLeague')['feeValue'].sum().sort_values(ascending=False)[:30].plot.pie(figsize=(6,6))


Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x10cc88c50>

In [17]:
#total number of transfers from each league to NL1 (Dutch Top Tier) - first transfer to league only
transfers[((transfers['toCountry'] != transfers['fromCountry']))&(transfers['toLeague'] == 'NL1')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('fromLeague')['id'].count().sort_values(ascending=False)[:40].plot.bar(figsize=(20,5))


Out[17]:
<matplotlib.axes._subplots.AxesSubplot at 0x10d3afbd0>

In [18]:
#total number of transfers to each league from GB2 (Football League Championship) - first transfer from league only
transfers[((~transfers['toCountry'].isin(['England','Scotland'])))&(transfers['fromLeague'] == 'GB2')&(transfers['season'] > 2000)].drop_duplicates(subset=['id'],keep='last').groupby('toLeague')['id'].count().sort_values(ascending=False)[:40].plot.bar(figsize=(20,5))


Out[18]:
<matplotlib.axes._subplots.AxesSubplot at 0x10b1a3750>

In [3]:
nonloans[(nonloans['toCountry']!=nonloans['fromCountry'])&(nonloans['fromLeague'].isin(['GB1','ES1','L1','IT1','FR1','NL1','PO1']))] \
    .rename(columns={'Age':'age','fromLeague':'origin'}).groupby(['age','origin'])['id'].count().unstack() \
    .rolling(window=3,center=False).mean().rename(columns={'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)'}).plot.line(figsize=(9,6),title='Number of International Transfers, by Age & Origin')


Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x107935cd0>

In [2]:
nonloans[(nonloans['toCountry']!=nonloans['fromCountry'])&(nonloans['toLeague'].isin(['GB1','ES1','L1','IT1','FR1','NL1','PO1']))] \
    .rename(columns={'Age':'age','toLeague':'destination'}).groupby(['age','destination'])['id'].count().unstack() \
    .rolling(window=3,center=False).mean().rename(columns={'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)'}).plot.line(figsize=(9,6),title='Number of International Transfers, by Age & Destination')


Out[2]:
<matplotlib.axes._subplots.AxesSubplot at 0x1093ef7d0>

In [23]:
transfers[transfers['feeValue']>0].drop_duplicates('id')['Player\'s agent id'].fillna('-1').value_counts()


Out[23]:
-1        2643
96.0       273
96.0       222
1207.0      85
1207.0      67
1635.0      57
674.0       56
190.0       50
946.0       50
193.0       47
1635.0      45
344.0       44
1061.0      41
213.0       40
413.0       38
223.0       37
199.0       36
946.0       36
2295.0      34
1181.0      31
12.0        30
1.0         29
348.0       29
586.0       27
2106.0      26
1181.0      25
3.0         25
926.0       24
378.0       24
274.0       22
          ... 
2265.0       1
1966.0       1
2267.0       1
1452.0       1
1454.0       1
2273.0       1
1577.0       1
686.0        1
2227.0       1
2984         1
2146.0       1
2217.0       1
675.0        1
2150.0       1
2151.0       1
2074.0       1
621          1
2169.0       1
1663         1
2123.0       1
2177.0       1
2186.0       1
1126         1
2200.0       1
2823         1
2208.0       1
2989         1
2212.0       1
3381         1
2356         1
Name: Player's agent id, dtype: int64

In [15]:
z=transfers.groupby(['playersAgentId','period'])['feeValue'].sum().unstack()#.sort_values('feeValue',ascending=False)
z#['avg fee']=z['feeValue']/z['id']
#z['avg mv']=z['mv']/z['id']
#z[z['id']>100].sort_values('avg fee',ascending=False)
z.join(agentIdTable)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-15-baa0b4960d09> in <module>()
      4 #z['avg mv']=z['mv']/z['id']
      5 #z[z['id']>100].sort_values('avg fee',ascending=False)
----> 6 z.join(agentIdTable)

NameError: name 'agentIdTable' is not defined

In [9]:
def toFromMismatch(df):
    #return (df['fromTeamId'].tolist()[:-1]==df['toTeamId'].tolist()[1:])
    #return (df['fromCountry'].tolist()[:-1]==df['toCountry'].tolist()[1:]) or df['fromCountry']
    return (df['fromCountry'].tolist()[:-1]==df['toCountry'].tolist()[1:])

topids=[186423, 39356, 5689, 3335, 75856 ]

z=nonloans.groupby('id').apply(toFromMismatch).sort_values()
z

In [103]:
nonloans[-2:]


Out[103]:
id playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... facebook instagram twitter website feeValue isLoan age ageFloat period countryChain
148183 201336 Andrea Mancini 2010-11-01 2010 Italy ITJ1 14848 Bologna England GB21 ... NaN NaN NaN NaN 0.0 False 18.0 18.218033 (2005, 2010] Italy->England->Spain->Hungary->United States
148184 201336 Andrea Mancini 2009-07-01 2009 Italy Other Italy 24432 Inter Youth Italy ITJ2 ... NaN NaN NaN NaN 0.0 False 16.0 16.881935 (2005, 2010] Italy->England->Spain->Hungary->United States

2 rows × 60 columns


In [27]:
from itertools import groupby

def getCountryChain(df):
    return [x[0] for x in groupby(df[-1:][df[-1:].fromCountry.notnull()].fromCountry.tolist() + df[df.toCountry.notnull()].toCountry.tolist()[::-1])]

def getLeagueChain(df):
    return [x[0] for x in groupby(df[-1:][df[-1:].fromLeague.notnull()].fromLeague.tolist() + df[df.toLeague.notnull()].toLeague.tolist()[::-1])]


z=nonloans.groupby('id').apply(getCountryChain).sort_values().apply(lambda x:'->'.join(x)).rename('countryChain')
z.value_counts()


Out[27]:
Italy                                                                               1572
Turkey                                                                              1368
England                                                                             1172
Germany                                                                             1143
Greece                                                                              1116
Spain                                                                               1110
France                                                                              1071
Netherlands                                                                         1044
Romania                                                                             1020
Russia                                                                               854
Norway                                                                               848
Belgium                                                                              806
United States                                                                        772
Sweden                                                                               699
Ukraine                                                                              696
Bosnia-Herzegovina                                                                   689
Bulgaria                                                                             632
Serbia                                                                               562
Denmark                                                                              543
Portugal                                                                             539
Croatia                                                                              503
Cyprus                                                                               346
Lithuania                                                                            324
France->Belgium                                                                      119
Brazil->Portugal                                                                     109
Germany->Turkey                                                                      109
Brazil->Portugal->Brazil                                                             105
Brazil                                                                               103
Belgium->Netherlands->Belgium                                                         90
France->England                                                                       82
                                                                                    ... 
Serbia->Romania->Serbia->Macedonia->Serbia                                             1
Georgia->Greece->Georgia->Azerbaijan->Georgia                                          1
Spain->Greece->Argentina->United States                                                1
Portugal->England->Cyprus                                                              1
Portugal->Finland->Latvia                                                              1
Greece->Cyprus->Greece->Bulgaria->Cyprus->Greece                                       1
Cameroon->France->England->Germany->Switzerland->England->Greece                       1
Slovenia->Austria->Germany->Austria->Israel->Serbia->Austria->Slovenia                 1
Colombia->Brazil->United States->Colombia                                              1
Brazil->Japan->Brazil->Russia->Brazil->China                                           1
France->Bulgaria->Switzerland                                                          1
Brazil->Lithuania->Poland->Brazil                                                      1
Brazil->Portugal->Poland->Portugal                                                     1
Denmark->Australia->Denmark                                                            1
Colombia->Portugal->Colombia->Mexico                                                   1
Iran->Singapore->Iran->Greece->Germany->Iran->Singapore                                1
Serbia->France->Belgium->United Arab Emirates->Serbia->Turkey->France                  1
Romania->Germany->Ukraine                                                              1
Denmark->Kazakhstan                                                                    1
Costa Rica->Cyprus->Greece->Costa Rica->Honduras->Costa Rica->Australia                1
Spain->United Arab Emirates->Italy->Spain                                              1
Cape Verde->France                                                                     1
Croatia->England->Ukraine->United States                                               1
Serbia->Bosnia-Herzegovina->Finland                                                    1
Romania->Italy->Romania->Turkey->Romania->Russia->Bulgaria->Romania                    1
Bosnia-Herzegovina->Croatia->Israel->Slovenia->Croatia->Albania->Cyprus->Croatia       1
France->England->Switzerland->Norway                                                   1
Albania->Germany->Italy->Germany->Poland->Germany                                      1
Nigeria->France->Germany                                                               1
Romania->Belgium->Portugal->Russia->Belgium->Portugal->Morocco                         1
Name: countryChain, dtype: int64

In [ ]:
w=nonloans.groupby('id').apply(getLeagueChain).sort_values().apply(lambda x:'->'.join(x)).rename('getLeagueChain')
w=w.rename('getLeagueChain')
w.value_counts()

In [32]:
nonloans=nonloans.drop('countryChain',axis=1,errors='ignore').merge(DataFrame(z),right_index=True,left_on='id',how='left')
nonloans=nonloans.drop('leagueChain',axis=1,errors='ignore').merge(DataFrame(w),right_index=True,left_on='id',how='left')

In [31]:
z[(z.str.contains('Serbia->Hungary'))].value_counts()[:20].plot.barh()


Out[31]:
<matplotlib.axes._subplots.AxesSubplot at 0x114b24d50>

In [33]:
nonloans[nonloans.countryChain.str.contains('Serbia->Hungary')]


Out[33]:
id playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... twitter website feeValue isLoan age ageFloat period getLeagueChain_x countryChain getLeagueChain_y
43895 42248 Dusan Vasiljevic 2015-08-27 2015 Austria Other Austria 7445 SC Ritzing Hungary UNG1 ... NaN NaN 0.0 False 33.0 33.306639 (2010, 2015] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43896 42248 Dusan Vasiljevic 2015-07-01 2015 NaN NaN 515 Unattached Austria Other Austria ... NaN NaN NaN False 33.0 33.150578 (2010, 2015] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43897 42248 Dusan Vasiljevic 2015-04-13 2014 Hungary UNG1 708 Újpest FC NaN NaN ... NaN NaN NaN False 32.0 32.934283 (2010, 2015] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43898 42248 Dusan Vasiljevic 2012-02-01 2011 Hungary UNG1 11107 Videoton FC Hungary UNG1 ... NaN NaN NaN False 29.0 29.739146 (2010, 2015] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43899 42248 Dusan Vasiljevic 2010-07-01 2010 Hungary UNG1 708 Újpest FC Hungary UNG1 ... NaN NaN 0.0 False 28.0 28.151160 (2005, 2010] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43900 42248 Dusan Vasiljevic 2010-02-01 2009 Czech Republic TS1 62 Slavia Prag Hungary UNG1 ... NaN NaN 0.0 False 27.0 27.740474 (2005, 2010] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43901 42248 Dusan Vasiljevic 2009-07-01 2009 Germany L2 25 Energie Cottbus Czech Republic TS1 ... NaN NaN 0.0 False 27.0 27.151824 (2005, 2010] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43902 42248 Dusan Vasiljevic 2008-01-01 2007 Hungary UNG1 6056 Kaposvári RFC Germany L1 ... NaN NaN 250000.0 False 25.0 25.654189 (2005, 2010] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43903 42248 Dusan Vasiljevic 2005-07-01 2005 Hungary Other Hungary 6049 Békéscsaba Hungary UNG1 ... NaN NaN 0.0 False 23.0 23.151742 (2000, 2005] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43904 42248 Dusan Vasiljevic 2004-07-01 2004 Serbia Other Serbia 4661 Radnicki Obrenovac Hungary UNG1 ... NaN NaN 0.0 False 22.0 22.152406 (2000, 2005] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43905 42248 Dusan Vasiljevic 2003-07-01 2003 Montenegro Other Montenegro 748 Mogren Budva Serbia Other Serbia ... NaN NaN 0.0 False 21.0 21.150332 (2000, 2005] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
43906 42248 Dusan Vasiljevic 2002-07-01 2002 Serbia Other Serbia 12514 Kolubara Montenegro Other Montenegro ... NaN NaN 0.0 False 20.0 20.150996 (2000, 2005] Other Serbia->Other Montenegro->Other Serbia->... Serbia->Montenegro->Serbia->Hungary->Germany->... Other Serbia->Other Montenegro->Other Serbia->...
85707 41783 Sinisa Radanovic 2014-01-01 2013 Serbia Other Serbia 2209 Borac Cacak NaN NaN ... NaN NaN NaN False 34.0 34.108845 (2010, 2015] SER1->PO1->SER1->CSL->SER1->UNG1->SER1 Serbia->Portugal->Serbia->China->Serbia->Hunga... SER1->PO1->SER1->CSL->SER1->UNG1->SER1
85708 41783 Sinisa Radanovic 2012-01-01 2011 Hungary UNG1 12423 Kecskeméti TE Serbia SER1 ... NaN NaN 0.0 False 32.0 32.107435 (2010, 2015] SER1->PO1->SER1->CSL->SER1->UNG1->SER1 Serbia->Portugal->Serbia->China->Serbia->Hunga... SER1->PO1->SER1->CSL->SER1->UNG1->SER1
85709 41783 Sinisa Radanovic 2011-01-01 2010 Serbia SER1 3140 Hajduk Kula Hungary UNG1 ... NaN NaN NaN False 31.0 31.108099 (2005, 2010] SER1->PO1->SER1->CSL->SER1->UNG1->SER1 Serbia->Portugal->Serbia->China->Serbia->Hunga... SER1->PO1->SER1->CSL->SER1->UNG1->SER1
85710 41783 Sinisa Radanovic 2010-07-01 2010 China CSL 3182 SD Luneng Serbia SER1 ... NaN NaN NaN False 30.0 30.604325 (2005, 2010] SER1->PO1->SER1->CSL->SER1->UNG1->SER1 Serbia->Portugal->Serbia->China->Serbia->Hunga... SER1->PO1->SER1->CSL->SER1->UNG1->SER1
85711 41783 Sinisa Radanovic 2010-01-01 2009 Serbia SER1 3140 Hajduk Kula China CSL ... NaN NaN 0.0 False 30.0 30.108763 (2005, 2010] SER1->PO1->SER1->CSL->SER1->UNG1->SER1 Serbia->Portugal->Serbia->China->Serbia->Hunga... SER1->PO1->SER1->CSL->SER1->UNG1->SER1
85712 41783 Sinisa Radanovic 2008-07-01 2008 Portugal PO1 2420 Vit. Guimarães Serbia SER1 ... NaN NaN NaN False 28.0 28.605652 (2005, 2010] SER1->PO1->SER1->CSL->SER1->UNG1->SER1 Serbia->Portugal->Serbia->China->Serbia->Hunga... SER1->PO1->SER1->CSL->SER1->UNG1->SER1
85713 41783 Sinisa Radanovic 2007-07-01 2007 Serbia SER1 3140 Hajduk Kula Portugal PO1 ... NaN NaN 220000.0 False 27.0 27.603578 (2005, 2010] SER1->PO1->SER1->CSL->SER1->UNG1->SER1 Serbia->Portugal->Serbia->China->Serbia->Hunga... SER1->PO1->SER1->CSL->SER1->UNG1->SER1
85714 41783 Sinisa Radanovic 2006-07-01 2006 Serbia SER1 904 Mladost Apatin Serbia SER1 ... NaN NaN 0.0 False 26.0 26.604242 (2005, 2010] SER1->PO1->SER1->CSL->SER1->UNG1->SER1 Serbia->Portugal->Serbia->China->Serbia->Hunga... SER1->PO1->SER1->CSL->SER1->UNG1->SER1
96278 33886 Zsombor Kerekes 2011-08-17 2011 Hungary Other Hungary 29753 Báránd Hungary Other Hungary ... NaN NaN 0.0 False 37.0 37.925488 (2010, 2015] Other Serbia->SER1->Other Hungary->UNG1->Other... Serbia->Hungary->Netherlands->Hungary Other Serbia->SER1->Other Hungary->UNG1->Other...
96279 33886 Zsombor Kerekes 2010-02-19 2009 Hungary UNG1 84 Debreceni VSC Hungary Other Hungary ... NaN NaN 0.0 False 36.0 36.436066 (2005, 2010] Other Serbia->SER1->Other Hungary->UNG1->Other... Serbia->Hungary->Netherlands->Hungary Other Serbia->SER1->Other Hungary->UNG1->Other...
96280 33886 Zsombor Kerekes 2007-07-10 2007 Netherlands NL1 403 Willem II Hungary UNG1 ... NaN NaN NaN False 33.0 33.821365 (2005, 2010] Other Serbia->SER1->Other Hungary->UNG1->Other... Serbia->Hungary->Netherlands->Hungary Other Serbia->SER1->Other Hungary->UNG1->Other...
96281 33886 Zsombor Kerekes 2005-07-01 2005 Hungary UNG1 84 Debreceni VSC Netherlands NL1 ... NaN NaN 200000.0 False 31.0 31.798052 (2000, 2005] Other Serbia->SER1->Other Hungary->UNG1->Other... Serbia->Hungary->Netherlands->Hungary Other Serbia->SER1->Other Hungary->UNG1->Other...
96282 33886 Zsombor Kerekes 2004-08-19 2004 Hungary UNG1 3233 Pécsi MFC Hungary UNG1 ... NaN NaN NaN False 30.0 30.932873 (2000, 2005] Other Serbia->SER1->Other Hungary->UNG1->Other... Serbia->Hungary->Netherlands->Hungary Other Serbia->SER1->Other Hungary->UNG1->Other...
96283 33886 Zsombor Kerekes 2004-02-25 2003 Hungary UNG1 84 Debreceni VSC Hungary Other Hungary ... NaN NaN NaN False 30.0 30.451002 (2000, 2005] Other Serbia->SER1->Other Hungary->UNG1->Other... Serbia->Hungary->Netherlands->Hungary Other Serbia->SER1->Other Hungary->UNG1->Other...
96284 33886 Zsombor Kerekes 2000-01-01 1999 Hungary Other Hungary 30641 Nagykanizsai TE 1866 Hungary UNG1 ... NaN NaN NaN False 26.0 26.300335 (1995, 2000] Other Serbia->SER1->Other Hungary->UNG1->Other... Serbia->Hungary->Netherlands->Hungary Other Serbia->SER1->Other Hungary->UNG1->Other...
96285 33886 Zsombor Kerekes 1999-07-01 1999 Serbia SER1 15276 Spartak Sub. Hungary Other Hungary ... NaN NaN NaN False 25.0 25.796560 (1995, 2000] Other Serbia->SER1->Other Hungary->UNG1->Other... Serbia->Hungary->Netherlands->Hungary Other Serbia->SER1->Other Hungary->UNG1->Other...
96286 33886 Zsombor Kerekes 1996-07-01 1996 Serbia Other Serbia 777 FK Becej Serbia SER1 ... NaN NaN NaN False 22.0 22.798552 (1995, 2000] Other Serbia->SER1->Other Hungary->UNG1->Other... Serbia->Hungary->Netherlands->Hungary Other Serbia->SER1->Other Hungary->UNG1->Other...
99028 46934 Aleksandar Ignjatovic 2012-07-01 2012 Serbia Other Serbia 2209 Borac Cacak Hungary UNG1 ... NaN NaN 0.0 False 24.0 24.222263 (2010, 2015] Other Serbia->SER1->UNG1 Serbia->Hungary Other Serbia->SER1->UNG1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
207180 101365 Boris Gujic 2013-01-01 2012 Bosnia-Herzegovina BOS1 282 FK Sarajevo Serbia Other Serbia ... NaN NaN 0.0 False 26.0 26.483774 (2010, 2015] Other Serbia->UNG1->BOS1->Other Serbia->BOS1 Serbia->Hungary->Bosnia-Herzegovina->Serbia->B... Other Serbia->UNG1->BOS1->Other Serbia->BOS1
207181 101365 Boris Gujic 2012-07-01 2012 Hungary UNG1 6056 Kaposvári RFC Bosnia-Herzegovina BOS1 ... NaN NaN 0.0 False 25.0 25.980000 (2010, 2015] Other Serbia->UNG1->BOS1->Other Serbia->BOS1 Serbia->Hungary->Bosnia-Herzegovina->Serbia->B... Other Serbia->UNG1->BOS1->Other Serbia->BOS1
207182 101365 Boris Gujic 2008-07-01 2008 Serbia Other Serbia 6620 CSK Celarevo Hungary UNG1 ... NaN NaN NaN False 21.0 21.979917 (2005, 2010] Other Serbia->UNG1->BOS1->Other Serbia->BOS1 Serbia->Hungary->Bosnia-Herzegovina->Serbia->B... Other Serbia->UNG1->BOS1->Other Serbia->BOS1
208136 60486 Novica Petrovic 2015-07-22 2015 Bosnia-Herzegovina Other Bosnia-Herzegovina 10667 FK Rudar Kakanj Bosnia-Herzegovina BOS1 ... NaN NaN NaN False 25.0 25.963572 (2010, 2015] Other Serbia->Other Hungary->Other Bosnia-Herz... Serbia->Hungary->Bosnia-Herzegovina Other Serbia->Other Hungary->Other Bosnia-Herz...
208137 60486 Novica Petrovic 2015-02-02 2014 NaN NaN 75 Unknown Bosnia-Herzegovina Other Bosnia-Herzegovina ... NaN NaN NaN False 25.0 25.498128 (2010, 2015] Other Serbia->Other Hungary->Other Bosnia-Herz... Serbia->Hungary->Bosnia-Herzegovina Other Serbia->Other Hungary->Other Bosnia-Herz...
208138 60486 Novica Petrovic 2013-12-01 2013 Hungary Other Hungary 6049 Békéscsaba NaN NaN ... NaN NaN 0.0 False 24.0 24.326304 (2010, 2015] Other Serbia->Other Hungary->Other Bosnia-Herz... Serbia->Hungary->Bosnia-Herzegovina Other Serbia->Other Hungary->Other Bosnia-Herz...
208139 60486 Novica Petrovic 2013-07-01 2013 Serbia Other Serbia 11046 FK Srem Hungary Other Hungary ... NaN NaN 0.0 False 23.0 23.907404 (2010, 2015] Other Serbia->Other Hungary->Other Bosnia-Herz... Serbia->Hungary->Bosnia-Herzegovina Other Serbia->Other Hungary->Other Bosnia-Herz...
208140 60486 Novica Petrovic 2011-07-01 2011 Serbia Other Serbia 8961 Radnicki Sombor Serbia Other Serbia ... NaN NaN NaN False 21.0 21.905994 (2010, 2015] Other Serbia->Other Hungary->Other Bosnia-Herz... Serbia->Hungary->Bosnia-Herzegovina Other Serbia->Other Hungary->Other Bosnia-Herz...
208141 60486 Novica Petrovic 2010-07-01 2010 Serbia Other Serbia 904 Mladost Apatin Serbia Other Serbia ... NaN NaN NaN False 20.0 20.906658 (2005, 2010] Other Serbia->Other Hungary->Other Bosnia-Herz... Serbia->Hungary->Bosnia-Herzegovina Other Serbia->Other Hungary->Other Bosnia-Herz...
208920 35924 Marko Djorovic 2012-07-01 2012 Serbia Other Serbia 3137 Backa Topola Serbia Other Serbia ... NaN NaN NaN False 29.0 29.194302 (2010, 2015] Other Serbia->UNG1->BU1->Other Serbia Serbia->Hungary->Bulgaria->Serbia Other Serbia->UNG1->BU1->Other Serbia
208921 35924 Marko Djorovic 2012-01-01 2011 Serbia Other Serbia 19488 Proleter Serbia Other Serbia ... NaN NaN NaN False 28.0 28.696003 (2010, 2015] Other Serbia->UNG1->BU1->Other Serbia Serbia->Hungary->Bulgaria->Serbia Other Serbia->UNG1->BU1->Other Serbia
208922 35924 Marko Djorovic 2011-08-01 2011 Serbia Other Serbia 2388 FK Novi Sad Serbia Other Serbia ... NaN NaN NaN False 28.0 28.277104 (2010, 2015] Other Serbia->UNG1->BU1->Other Serbia Serbia->Hungary->Bulgaria->Serbia Other Serbia->UNG1->BU1->Other Serbia
208923 35924 Marko Djorovic 2010-01-01 2009 Serbia Other Serbia 904 Mladost Apatin Serbia Other Serbia ... NaN NaN NaN False 26.0 26.697331 (2005, 2010] Other Serbia->UNG1->BU1->Other Serbia Serbia->Hungary->Bulgaria->Serbia Other Serbia->UNG1->BU1->Other Serbia
208924 35924 Marko Djorovic 2009-07-01 2009 NaN NaN 75 Unknown Serbia Other Serbia ... NaN NaN NaN False 26.0 26.193556 (2005, 2010] Other Serbia->UNG1->BU1->Other Serbia Serbia->Hungary->Bulgaria->Serbia Other Serbia->UNG1->BU1->Other Serbia
208925 35924 Marko Djorovic 2008-07-01 2008 Bulgaria BU1 967 Cherno More NaN NaN ... NaN NaN NaN False 25.0 25.194220 (2005, 2010] Other Serbia->UNG1->BU1->Other Serbia Serbia->Hungary->Bulgaria->Serbia Other Serbia->UNG1->BU1->Other Serbia
208926 35924 Marko Djorovic 2006-07-01 2006 Hungary UNG1 1391 Zalaegerszeg Bulgaria BU1 ... NaN NaN 0.0 False 23.0 23.192810 (2005, 2010] Other Serbia->UNG1->BU1->Other Serbia Serbia->Hungary->Bulgaria->Serbia Other Serbia->UNG1->BU1->Other Serbia
208927 35924 Marko Djorovic 2005-07-01 2005 Serbia Other Serbia 3140 Hajduk Kula Hungary UNG1 ... NaN NaN 0.0 False 22.0 22.193474 (2000, 2005] Other Serbia->UNG1->BU1->Other Serbia Serbia->Hungary->Bulgaria->Serbia Other Serbia->UNG1->BU1->Other Serbia
213525 58300 Pavle Velimirovic 2016-02-09 2015 Montenegro MNE1 1004 FK Zeta Golubovac Bosnia-Herzegovina Other Bosnia-Herzegovina ... NaN NaN NaN False 25.0 25.832153 (2010, 2015] Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1... Serbia->Hungary->Montenegro->Poland->Bulgaria-... Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1...
213526 58300 Pavle Velimirovic 2014-07-01 2014 Malta Other Malta 26490 Rabat Ajax Montenegro MNE1 ... NaN NaN NaN False 24.0 24.222263 (2010, 2015] Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1... Serbia->Hungary->Montenegro->Poland->Bulgaria-... Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1...
213527 58300 Pavle Velimirovic 2013-08-02 2013 NaN NaN 75 Unknown Malta MAL1 ... NaN NaN NaN False 23.0 23.310540 (2010, 2015] Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1... Serbia->Hungary->Montenegro->Poland->Bulgaria-... Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1...
213528 58300 Pavle Velimirovic 2013-01-01 2012 Bulgaria BU1 712 FK Etar NaN NaN ... NaN NaN NaN False 22.0 22.727366 (2010, 2015] Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1... Serbia->Hungary->Montenegro->Poland->Bulgaria-... Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1...
213529 58300 Pavle Velimirovic 2012-11-07 2012 NaN NaN 75 Unknown Bulgaria BU1 ... NaN NaN NaN False 22.0 22.576781 (2010, 2015] Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1... Serbia->Hungary->Montenegro->Poland->Bulgaria-... Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1...
213530 58300 Pavle Velimirovic 2012-07-01 2012 Poland Other Poland 256 LKS Lodz NaN NaN ... NaN NaN 0.0 False 22.0 22.223591 (2010, 2015] Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1... Serbia->Hungary->Montenegro->Poland->Bulgaria-... Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1...
213531 58300 Pavle Velimirovic 2011-07-01 2011 Montenegro MNE1 12889 OFK Petrovac Poland PL1 ... NaN NaN 0.0 False 21.0 21.221517 (2010, 2015] Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1... Serbia->Hungary->Montenegro->Poland->Bulgaria-... Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1...
213532 58300 Pavle Velimirovic 2010-01-01 2009 Hungary UNG1 12423 Kecskeméti TE Montenegro MNE1 ... NaN NaN 0.0 False 19.0 19.726620 (2005, 2010] Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1... Serbia->Hungary->Montenegro->Poland->Bulgaria-... Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1...
213533 58300 Pavle Velimirovic 2008-07-01 2008 Serbia Other Serbia 12373 FK Partizan U19 Hungary UNG1 ... NaN NaN 0.0 False 18.0 18.223509 (2005, 2010] Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1... Serbia->Hungary->Montenegro->Poland->Bulgaria-... Other Serbia->UNG1->MNE1->PL1->BU1->MAL1->MNE1...
221631 95626 Ivan Ristic 2012-01-01 2011 Sweden SE1 7406 Syrianska FC NaN NaN ... NaN NaN NaN False 36.0 36.975434 (2010, 2015] SER1->UNG1->Other Sweden Serbia->Hungary->Sweden SER1->UNG1->Other Sweden
221632 95626 Ivan Ristic 2006-01-01 2005 Hungary UNG1 11107 FC Fehérvár Sweden Other Sweden ... NaN NaN NaN False 30.0 30.976680 (2000, 2005] SER1->UNG1->Other Sweden Serbia->Hungary->Sweden SER1->UNG1->Other Sweden
221633 95626 Ivan Ristic 2002-07-01 2002 Serbia SER1 902 Rad Hungary UNG1 ... NaN NaN NaN False 27.0 27.472159 (2000, 2005] SER1->UNG1->Other Sweden Serbia->Hungary->Sweden SER1->UNG1->Other Sweden
221634 95626 Ivan Ristic 2001-07-01 2001 Serbia SER1 448 Vojvodina Serbia SER1 ... NaN NaN NaN False 26.0 26.472823 (2000, 2005] SER1->UNG1->Other Sweden Serbia->Hungary->Sweden SER1->UNG1->Other Sweden

742 rows × 62 columns


In [54]:
transfers[transfers.feeValue>0]['feeValue'].median()


Out[54]:
1000000.0

In [7]:
transfers[(transfers.feeValue>0)&(transfers.season>=1990)].groupby('season')['feeValue'].describe().unstack().drop(['count','std','max'],errors='ignore',axis=1).plot.line()


Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x1090f7210>

In [158]:
w[(w.str.contains('ZYP1'))&(z.str.contains('->'))].value_counts()[:20].plot.barh()


Out[158]:
<matplotlib.axes._subplots.AxesSubplot at 0x11ed0c510>

In [138]:
z[z.apply(lambda x:len(x.split('->')))>12]


Out[138]:
id
16594     Argentina->Uruguay->Argentina->Mexico->Ecuador...
103946    Belarus->Russia->Belarus->Russia->Turkey->Russ...
12151     Brazil->France->Japan->Brazil->Saudi Arabia->J...
56124     Brazil->Germany->Brazil->Honduras->Mexico->Hon...
17474     Brazil->Italy->Portugal->Brazil->Italy->Turkey...
15094     Brazil->Switzerland->Brazil->Japan->Russia->Me...
26679     Cameroon->Switzerland->Qatar->Morocco->Germany...
103230    Colombia->England->Bulgaria->Argentina->Japan-...
90695     Colombia->Italy->Colombia->Uruguay->Colombia->...
4246      Croatia->Bosnia-Herzegovina->Croatia->Japan->B...
28443     Egypt->Greece->Saudi Arabia->Cyprus->Turkey->C...
12098     France->Germany->Algeria->Germany->Turkey->Fra...
26426     Iceland->Norway->England->Denmark->Norway->Swe...
43951     Lithuania->Russia->Portugal->Russia->Latvia->R...
9992      Macedonia->Sweden->Macedonia->Slovenia->Turkey...
52028     Panama->Colombia->Panama->Colombia->Panama->Co...
45474     Panama->Colombia->United Arab Emirates->Panama...
14126     Portugal->Bahrain->Germany->Kuwait->Italy->Bul...
13748     Serbia->Belgium->Serbia->Belgium->Serbia->Aust...
142533    Uruguay->Argentina->Uruguay->Chile->Venezuela-...
72640     Venezuela->Argentina->Venezuela->Ecuador->Vene...
Name: countryChain, dtype: object

In [143]:
nonloans[nonloans.countryChain=='Netherlands->Bulgaria->Netherlands'].drop_duplicates('id')[['id','playerName','Nationality','currentClub','Age','countryChain']]


Out[143]:
id playerName Nationality currentClub Age countryChain
97522 57006 Ingmar Maayen Netherlands SVV Scheveningen 28.0 Netherlands->Bulgaria->Netherlands
98278 56355 Mitchell Burgzorg Netherlands Almere City FC 28.0 Netherlands->Bulgaria->Netherlands
98581 82925 Kai van Hese Netherlands Quick Den Haag 26.0 Netherlands->Bulgaria->Netherlands
98996 122173 Marlon Pereira Netherlands SC Cambuur-Leeuwarden 29.0 Netherlands->Bulgaria->Netherlands
99310 31117 Jerson Ribeiro Netherlands SC Feyenoord Rotterdam 28.0 Netherlands->Bulgaria->Netherlands
99340 45534 Christian Supusepa Netherlands Sparta Rotterdam 27.0 Netherlands->Bulgaria->Netherlands
99520 84381 Karim Mossaoui Netherlands Unattached 28.0 Netherlands->Bulgaria->Netherlands
100894 203914 Jeroen Lumu Netherlands FC Dordrecht 20.0 Netherlands->Bulgaria->Netherlands

In [89]:
nonloans[nonloans.id== 151197 ]


Out[89]:
id playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... facebook instagram twitter website feeValue isLoan age ageFloat period countryChain
127719 151197 Chisamba Lungu 2010-07-01 2010 Georgia GEO1 26558 Baia Zugdidi Russia RU2 ... NaN NaN NaN NaN 50000.0 False 19.0 19.414499 (2005, 2010] Zambia->Georgia->Russia
127720 151197 Chisamba Lungu 2009-07-01 2009 Zambia Other Zambia 14578 Zanaco FC Georgia GEO1 ... NaN NaN NaN NaN NaN False 18.0 18.415163 (2005, 2010] Zambia->Georgia->Russia
127721 151197 Chisamba Lungu 2007-07-01 2007 Zambia Other Zambia 464 Own U19 Zambia Other Zambia ... NaN NaN NaN NaN NaN False 16.0 16.413753 (2005, 2010] Zambia->Georgia->Russia

3 rows × 60 columns


In [48]:
z


Out[48]:
id
25473                                                    []
57459                                                    []
7628                                                     []
105994                                                   []
57819                                                    []
30799                                                    []
201805                                                   []
203518                                                   []
39369                                                    []
7462                                                     []
58598                                                    []
142525                                                   []
255436                                                   []
100794                                                   []
59668                                                    []
44657                                                    []
145483                                                   []
134019                                                   []
22400                                                    []
223332                                                   []
127026                                                   []
23968                                                    []
23943                                                    []
23917                                                    []
23348                                                    []
133091                                                   []
290595                                                   []
214950                                                   []
131847                                                   []
48724                                                    []
                                ...                        
55292                   [Vietnam, France, Bulgaria, France]
46650     [Vietnam, Italy, Croatia, Slovenia, Poland, Hu...
81497                                [Vietnam, Netherlands]
99908                   [Vietnam, Nigeria, Russia, Nigeria]
13228     [Vietnam, Portugal, United States, Greece, Bra...
29067                       [Vietnam, Spain, Greece, Spain]
28541     [Vietnam, Thailand, Singapore, France, England...
44747                              [Vietnam, United States]
203869                                              [Wales]
197830                                              [Wales]
4126                                       [Wales, England]
121256                                     [Wales, England]
9162                                       [Wales, England]
66531                                      [Wales, England]
142728                                     [Wales, England]
22229                                      [Wales, England]
3606                                       [Wales, England]
4252                                       [Wales, England]
173584                                     [Wales, England]
7337                                       [Wales, England]
4765                      [Wales, England, Norway, England]
12737                   [Wales, England, Scotland, England]
121252                     [Wales, England, Wales, England]
6939      [Wales, Israel, Norway, Spain, England, Spain,...
57056                  [Wales, New Zealand, Wales, England]
124843                    [Zambia, Congo DR, Sudan, France]
46005     [Zambia, South Africa, China, Greece, Germany,...
33899                         [Zimbabwe, Belgium, Zimbabwe]
68479     [Zimbabwe, South Africa, Kenya, Cyprus, Zimbab...
71095               [Zimbabwe, South Africa, United States]
dtype: object

In [46]:
transfers[transfers.countryChain=='Cyprus->Portugal'][['id','Nationality']]


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-46-9cfe59ae4f31> in <module>()
----> 1 transfers[transfers.countryChain=='Cyprus->Portugal'][['id','Nationality']]

/Users/sunkevin/anaconda/lib/python2.7/site-packages/pandas/core/generic.pyc in __getattr__(self, name)
   2670             if name in self._info_axis:
   2671                 return self[name]
-> 2672             return object.__getattribute__(self, name)
   2673 
   2674     def __setattr__(self, name, value):

AttributeError: 'DataFrame' object has no attribute 'countryChain'

In [35]:
DataFrame({'loans':loans.groupby('season')['feeValue'].sum()}).join(DataFrame({'nonloans':nonloans.groupby('season')['feeValue'].sum()/30})).plot.line()


Out[35]:
<matplotlib.axes._subplots.AxesSubplot at 0x10ab8ec90>

In [51]:
t=loans.groupby(['fromCountry','toCountry']).agg({'feeValue':'sum','id':'count'}).sort_values('feeValue',ascending=False)
t['avgFee']=t.feeValue/t.id
t.sort_values('avgFee',ascending=False)


Out[51]:
feeValue id avgFee
fromCountry toCountry
England United Arab Emirates 7000000.0 2 3.500000e+06
Turkey United Arab Emirates 4500000.0 2 2.250000e+06
Qatar Italy 3500000.0 2 1.750000e+06
Turkey Italy 6050000.0 4 1.512500e+06
Egypt United Arab Emirates 3500000.0 3 1.166667e+06
United Arab Emirates Italy 1100000.0 1 1.100000e+06
Mexico England 900000.0 1 9.000000e+05
Serbia United Arab Emirates 1800000.0 2 9.000000e+05
Korea, South England 825000.0 1 8.250000e+05
Ukraine England 8085000.0 10 8.085000e+05
Sweden Malaysia 800000.0 1 8.000000e+05
Switzerland Korea, South 800000.0 1 8.000000e+05
Germany Italy 9350000.0 12 7.791667e+05
Romania France 700000.0 1 7.000000e+05
England Qatar 2000000.0 3 6.666667e+05
Qatar Belgium 1315000.0 2 6.575000e+05
Netherlands Mexico 1280000.0 2 6.400000e+05
Turkey Greece 1875000.0 3 6.250000e+05
Iran Germany 1250000.0 2 6.250000e+05
Italy Germany 14300000.0 23 6.217391e+05
Portugal Qatar 1860000.0 3 6.200000e+05
Egypt England 4250000.0 7 6.071429e+05
Austria Russia 1800000.0 3 6.000000e+05
Belarus Germany 600000.0 1 6.000000e+05
Spain Germany 15940000.0 28 5.692857e+05
Germany Spain 9550000.0 18 5.305556e+05
South Africa Serbia 530000.0 1 5.300000e+05
Russia Germany 4700000.0 9 5.222222e+05
Turkey England 4100000.0 8 5.125000e+05
Spain 4040000.0 8 5.050000e+05
... ... ... ... ...
Uruguay Switzerland 0.0 1 0.000000e+00
Serbia Malta 0.0 2 0.000000e+00
Moldova 0.0 1 0.000000e+00
Montenegro 0.0 31 0.000000e+00
Myanmar 0.0 1 0.000000e+00
Norway 0.0 2 0.000000e+00
Poland 0.0 2 0.000000e+00
Portugal 0.0 7 0.000000e+00
Saudi Arabia Germany 0.0 1 0.000000e+00
France 0.0 1 0.000000e+00
England 0.0 4 0.000000e+00
Brazil 0.0 2 0.000000e+00
Scotland Sweden 0.0 4 0.000000e+00
Switzerland 0.0 1 0.000000e+00
Turkey 0.0 2 0.000000e+00
United Arab Emirates 0.0 1 0.000000e+00
United States 0.0 2 0.000000e+00
Denmark 0.0 6 0.000000e+00
Uruguay Turkey 0.0 4 0.000000e+00
Scotland China 0.0 1 0.000000e+00
Australia 0.0 3 0.000000e+00
Russia United States 0.0 1 0.000000e+00
Uruguay 0.0 2 0.000000e+00
Uzbekistan 0.0 3 0.000000e+00
Rwanda Sweden 0.0 1 0.000000e+00
Uruguay Venezuela 0.0 2 0.000000e+00
San Marino Italy 0.0 1 0.000000e+00
Saudi Arabia Azerbaijan 0.0 1 0.000000e+00
Belgium 0.0 2 0.000000e+00
Zimbabwe Zimbabwe 0.0 1 0.000000e+00

1920 rows × 3 columns


In [57]:
loans[loans.toCountry=='United Arab Emirates'].groupby('fromCountry').agg({'feeValue':'sum','id':'count'}).sort_values('feeValue',ascending=False)


Out[57]:
feeValue id
fromCountry
England 7000000.0 2
Turkey 4500000.0 2
Egypt 3500000.0 3
Brazil 2483000.0 9
Serbia 1800000.0 2
Tunisia 500000.0 2
France 300000.0 8
Uruguay 200000.0 1
Senegal 100000.0 1
Australia 0.0 1
Romania 0.0 1
United Arab Emirates 0.0 3
Switzerland 0.0 2
Scotland 0.0 1
Saudi Arabia 0.0 1
Russia 0.0 1
Netherlands 0.0 1
Qatar 0.0 1
Portugal 0.0 2
Azerbaijan 0.0 1
Morocco 0.0 1
Japan 0.0 1
Italy 0.0 3
Hungary 0.0 1
Germany 0.0 1
China 0.0 1
Bulgaria 0.0 1
Belgium 0.0 1
Uzbekistan 0.0 1

In [102]:
t.date.str.split('-',expand=True)[1].fillna('0').apply(int)<7


Out[102]:
0         False
1         False
2          True
3          True
4          True
5         False
6         False
7         False
8          True
9         False
10        False
11        False
12        False
13        False
14        False
15        False
16         True
17        False
18        False
19        False
20        False
21         True
22         True
23        False
24         True
25        False
26        False
27        False
28         True
29        False
          ...  
302842     True
302843    False
302844    False
302845    False
302846    False
302847    False
302848    False
302849     True
302850    False
302851    False
302852    False
302853    False
302854     True
302855    False
302856    False
302857    False
302858    False
302859     True
302860    False
302861     True
302862    False
302863    False
302864    False
302865    False
302866     True
302867    False
302868    False
302869    False
302870     True
302871    False
Name: 1, dtype: bool

In [104]:
t=nonloans
a=t[(t.season==2011)&(t.fromCountry!=t.toCountry)&(t.date.str.split('-',expand=True)[1].fillna('0').apply(int)<7)].groupby('fromCountry')['id'].count()
b=t[(t.season==2011)&(t.fromCountry!=t.toCountry)&(t.date.str.split('-',expand=True)[1].fillna('0').apply(int)<7)].groupby('toCountry')['id'].count()
c=DataFrame({'from':a,'to':b})
c['total']=c['from']+c['to']
c.sort_values('total',ascending=False)


Out[104]:
from to total
United States 111.0 149.0 260.0
Brazil 98.0 158.0 256.0
Sweden 124.0 87.0 211.0
Serbia 120.0 81.0 201.0
Germany 79.0 98.0 177.0
Norway 104.0 70.0 174.0
England 92.0 78.0 170.0
Bosnia-Herzegovina 91.0 76.0 167.0
Ukraine 81.0 84.0 165.0
Russia 111.0 52.0 163.0
Austria 65.0 97.0 162.0
Finland 102.0 58.0 160.0
Romania 76.0 78.0 154.0
Poland 78.0 71.0 149.0
Hungary 79.0 57.0 136.0
Croatia 84.0 50.0 134.0
Lithuania 80.0 42.0 122.0
Scotland 72.0 45.0 117.0
France 50.0 65.0 115.0
Bulgaria 59.0 52.0 111.0
Turkey 57.0 54.0 111.0
Cyprus 74.0 33.0 107.0
Greece 72.0 32.0 104.0
Belgium 49.0 51.0 100.0
Kazakhstan 35.0 65.0 100.0
Switzerland 50.0 48.0 98.0
Czech Republic 45.0 53.0 98.0
Slovakia 58.0 37.0 95.0
Italy 49.0 45.0 94.0
Denmark 53.0 38.0 91.0
... ... ... ...
Zimbabwe 1.0 1.0 2.0
Bermuda 1.0 NaN NaN
Cambodia NaN 1.0 NaN
Gabon 1.0 NaN NaN
Guine 1.0 NaN NaN
Haiti NaN 1.0 NaN
Iraq NaN 1.0 NaN
Jamaica 4.0 NaN NaN
Jordan NaN 1.0 NaN
Kenya NaN 1.0 NaN
Kosovo 3.0 NaN NaN
Kyrgyzstan NaN 1.0 NaN
Lebanon 2.0 NaN NaN
Liberia NaN 1.0 NaN
Libya 3.0 NaN NaN
Macao NaN 1.0 NaN
Maldives NaN 1.0 NaN
Mozambique NaN 1.0 NaN
Myanmar NaN 3.0 NaN
Palästina 1.0 NaN NaN
Philippines NaN 1.0 NaN
Rwanda 2.0 NaN NaN
Réunion NaN 1.0 NaN
San Marino 1.0 NaN NaN
Senegal 6.0 NaN NaN
Sierra Leone 3.0 NaN NaN
Sudan 1.0 NaN NaN
Tanzania NaN 1.0 NaN
Turkmenistan NaN 1.0 NaN
Zambia 2.0 NaN NaN

129 rows × 3 columns


In [147]:
t=transfers[transfers.season>=2010]
domestic=t[t.fromCountry==t.toCountry].groupby('fromLeague').sum()['feeValue'].sort_values(ascending=False)
international=t[t.fromCountry!=t.toCountry].groupby('toLeague').sum()['feeValue'].sort_values(ascending=False)
tt=DataFrame({'domestic':domestic,'international':international})
#tt['international']=tt.internationalOut+tt.internationalIn
tt['total']=tt.domestic+tt.international
tt.sort_values('total',ascending=False)[:10]#.sum() #['total'].plot.pie()


Out[147]:
domestic international total
GB1 1.704800e+09 3.596652e+09 5.301452e+09
IT1 1.626748e+09 1.404262e+09 3.031010e+09
ES1 6.382000e+08 1.726380e+09 2.364580e+09
L1 6.966250e+08 1.051850e+09 1.748475e+09
FR1 4.548750e+08 9.456450e+08 1.400520e+09
RU1 4.086400e+08 8.594420e+08 1.268082e+09
GB2 6.318010e+08 1.639980e+08 7.957990e+08
TR1 1.595090e+08 4.816610e+08 6.411700e+08
PO1 6.817800e+07 4.682890e+08 5.364670e+08
UKR1 6.219500e+07 3.797250e+08 4.419200e+08

In [202]:
def avgAge(t):
    allIn=t[t.toLeague.isin(leagueList)].groupby('toCountry')['ageFloat'].mean().sort_values()
    allOut=t[t.fromLeague.isin(leagueList)].groupby('fromCountry')['ageFloat'].mean().sort_values()
    freeIn=t[t.toLeague.isin(leagueList)&(t.feeValue==0)].groupby('toCountry')['ageFloat'].mean().sort_values()
    freeOut=t[t.fromLeague.isin(leagueList)&(t.feeValue==0)].groupby('fromCountry')['ageFloat'].mean().sort_values()
    paidIn=t[t.toLeague.isin(leagueList)&(t.feeValue>0)].groupby('toCountry')['ageFloat'].mean().sort_values()
    paidOut=t[t.fromLeague.isin(leagueList)&(t.feeValue>0)].groupby('fromCountry')['ageFloat'].mean().sort_values()
    z=DataFrame({'all imports':allIn,'all exports':allOut,'free imports':freeIn,'free exports':freeOut,'paid imports':paidIn,'paid exports':paidOut}).sort_values('all imports')
    z=z[['all imports', 'all exports', 'paid imports', 'paid exports', 'free imports', 'free exports']]
    z.columns.name='average age'
    return z.reset_index().rename(columns={'index':'country'})

output=nonloans[(nonloans.fromCountry!=nonloans.toCountry)&(nonloans.season>2000)].groupby('period').apply(avgAge).unstack(level=0).swaplevel(axis=1).sort_index(axis=1,level=0)
output.to_excel('../data/analysis/average_age.xlsx')

In [210]:
t=nonloans[(nonloans.fromCountry!=nonloans.toCountry)&(nonloans.season>2000)&(nonloans.toCountry=='Cyprus')&(nonloans.Nationality!='Cyprus')]
t.groupby('Nationality')['id'].count().sort_values(ascending=False)


Out[210]:
Nationality
Portugal                 198
Greece                   166
Brazil                   150
Spain                     92
Serbia                    65
Argentina                 64
Slovenia                  58
Poland                    58
Romania                   56
Bulgaria                  53
France                    52
Netherlands               47
Hungary                   45
Nigeria                   40
Croatia                   33
Macedonia                 32
Slovakia                  29
Czech Republic            28
Ghana                     28
Cape Verde                27
Georgia                   27
Belgium                   25
Germany                   23
Angola                    20
Israel                    20
Bosnia-Herzegovina        18
Venezuela                 17
Senegal                   15
Latvia                    14
Cameroon                  13
                        ... 
Suriname                   2
Montserrat                 2
Colombia                   2
Paraguay                   2
United States              2
Gabon                      2
Turkey                     2
Denmark                    2
Bolivia                    2
Equatorial Guinea          2
Rwanda                     2
Iraq                       2
Uganda                     1
Burkina Faso               1
Norway                     1
El Salvador                1
Ethiopia                   1
Sao Tome and Principe      1
Réunion                    1
Russia                     1
Honduras                   1
Hongkong                   1
Qatar                      1
Iceland                    1
Iran                       1
Jersey                     1
Lebanon                    1
Mauritius                  1
Panama                     1
Afghanistan                1
Name: id, dtype: int64

In [178]:
{'all imports':allIn,'all exports':allOut,'free imports':freeIn,'free exports':freeOut,'paid imports':paidIn,'paid exports':paidOut}.keys()


Out[178]:
['all imports',
 'paid exports',
 'paid imports',
 'all exports',
 'free exports',
 'free imports']

In [131]:
transfers.groupby('season').agg({'id':'count','feeValue':'sum'}).ix[[1994,1999,2005,2011]]


Out[131]:
feeValue id
season
1994 1.652780e+08 1896
1999 1.468608e+09 5495
2005 1.772553e+09 15744
2011 3.260172e+09 28405

In [143]:
t=transfers[transfers.fromCountry=='England']
t=t[t.season==2010]
t.groupby('fromTeamId').sum()[['feeValue']].join(DataFrame({'teamName':teamIdMap})).sort_values('feeValue',ascending=False)


Out[143]:
feeValue teamName
fromTeamId
31 101500000.0 Liverpool
289 41775000.0 Sunderland
762 41750000.0 Newcastle
281 37608000.0 Manchester City
405 28400000.0 Aston Villa
985 18390000.0 Manchester Utd.
631 16500000.0 Chelsea
1020 16480000.0 Portsmouth FC
931 12360000.0 Fulham FC
11 9600000.0 Arsenal
3008 9000000.0 Hull City
641 8450000.0 Middlesbrough
1132 7200000.0 Burnley FC
1032 7070000.0 Reading
512 6775000.0 Stoke City
29 6600000.0 Everton
543 5440000.0 Wolves
379 4950000.0 West Ham
677 4435000.0 Ipswich
466 3400000.0 Preston NE
1071 3400000.0 Wigan
2964 3125000.0 Scunthorpe Utd.
1003 2990000.0 Leicester
148 2935000.0 Spurs
9252 2700000.0 Liverpool U21
358 2540000.0 Charlton
350 2530000.0 Sheffield Utd.
352 2060000.0 Swindon Town
984 1850000.0 West Brom
1035 1800000.0 Sheff Wed
... ... ...
8569 NaN Evesham United FC
9256 NaN Boro U21
9527 NaN Warrington Town FC
9955 NaN West Ham U18
12797 NaN Sunderland U18
12799 NaN Not. Forest U18
12801 NaN Wolves U18
12803 NaN Coventry U18
12804 NaN Crewe U18
12806 NaN Sheff Utd U18
12807 NaN Tranmere U18
12808 NaN Wigan U18
14389 NaN Leicester U18
14466 NaN Burnley U18
14482 NaN Hull U19
14629 NaN Huddersf. U18
14648 NaN Bournemouth U18
14984 NaN Plymouth U18
16282 NaN Shrewsbury U18
18619 NaN Northampton U19
21545 NaN Lancaster City
22666 NaN Whitley Bay
24707 NaN Aldershot U19
25136 NaN Wimbledon U18
26030 NaN St. Neots Town
31564 NaN Cray Wanderers FC
33615 NaN Redbridge FC
50677 NaN Chelsea Youth
50780 NaN Southampton Jgd
52299 NaN Dorking

235 rows × 2 columns


In [92]:
nonloans[nonloans.fromCountry=='Switzerland']


Out[92]:
id playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... dayOfDeath facebook instagram twitter website feeValue isLoan age ageFloat period
645 103679 Roberto Di Matteo 1993-07-01 00:00:00 1993 Switzerland Other Switzerland 116 FC Aarau Italy IT1 ... NaN NaN NaN NaN NaN 0.0 False 23.0 22.595947 NaN
646 103679 Roberto Di Matteo 1992-07-01 00:00:00 1992 Switzerland C1 260 FC Zürich Switzerland Other Switzerland ... NaN NaN NaN NaN NaN NaN False 22.0 21.593873 NaN
647 103679 Roberto Di Matteo 1991-07-01 00:00:00 1991 Switzerland Other Switzerland 1277 FC Schaffhausen Switzerland Other Switzerland ... NaN NaN NaN NaN NaN NaN False 21.0 20.594537 NaN
771 2888 Bernt Haas 2010-07-01 00:00:00 2010 Switzerland C1 257 FC St. Gallen NaN NaN ... NaN NaN NaN NaN NaN NaN False 32.0 31.735080 (2005, 2010]
776 2888 Bernt Haas 2000-07-01 00:00:00 2000 Switzerland C1 504 Grasshoppers England GB1 ... NaN NaN NaN NaN NaN 2100000.0 False 22.0 21.733506 (1995, 2000]
777 2888 Bernt Haas 1994-07-01 00:00:00 1994 Switzerland Other Switzerland 5502 GCZ II Switzerland C1 ... NaN NaN NaN NaN NaN NaN False 16.0 15.734752 NaN
1080 3089 Shaun Bartlett 2001-01-01 00:00:00 2000 Switzerland C1 260 FC Zürich England GB1 ... NaN NaN NaN NaN NaN 3000000.0 False 28.0 27.168251 (1995, 2000]
1652 3200 Igors Stepanovs 2006-04-01 00:00:00 2005 Switzerland C1 504 Grasshoppers Latvia LET1 ... NaN NaN NaN NaN NaN 0.0 False 29.0 28.947891 (2000, 2005]
1685 3210 Stéphane Henchoz 1995-07-01 00:00:00 1995 Switzerland Other Switzerland 625 Neuchâtel Xamax Germany L1 ... NaN NaN NaN NaN NaN 750000.0 False 21.0 20.318008 NaN
1686 3210 Stéphane Henchoz 1992-07-01 00:00:00 1992 Switzerland Other Switzerland 2053 FC Bulle Switzerland Other Switzerland ... NaN NaN NaN NaN NaN 0.0 False 18.0 17.317262 NaN
1687 3210 Stéphane Henchoz 1989-07-01 00:00:00 1989 Switzerland Other Switzerland 16610 Gruyère Jugend Switzerland Other Switzerland ... NaN NaN NaN NaN NaN NaN False 15.0 14.319254 NaN
2710 9676 Gérald Forschelet 2005-07-01 00:00:00 2005 Switzerland C1 625 Neuchâtel Xamax Belgium BE1 ... NaN NaN NaN NaN NaN 0.0 False 24.0 23.285899 (2000, 2005]
3304 3704 Corrado Grabbi 2009-07-01 00:00:00 2009 Switzerland C1 2047 AC Bellinzona NaN NaN ... NaN NaN NaN NaN NaN NaN False 34.0 33.429845 (2005, 2010]
3345 3715 Mart Poom 1994-07-01 00:00:00 1994 Switzerland Other Switzerland 850 FC Wil 1900 England Other England ... NaN NaN NaN NaN NaN 200000.0 False 22.0 21.911470 NaN
3377 3727 Alex Nyarko 2007-08-01 00:00:00 2007 Switzerland Other Switzerland 322 Yverdon-Sport NaN NaN ... NaN NaN NaN NaN NaN NaN False 34.0 33.213550 (2005, 2010]
3382 3727 Alex Nyarko 1997-07-01 00:00:00 1997 Switzerland C1 26 FC Basel Germany L1 ... NaN NaN NaN NaN NaN NaN False 24.0 23.214714 (1995, 2000]
4839 3227 Danny Tiatto 1998-07-01 00:00:00 1998 Switzerland Other Switzerland 747 FC Baden England Other England ... NaN NaN NaN NaN NaN 450000.0 False 25.0 24.613784 (1995, 2000]
4959 3808 Lucién Mettomo 2007-07-01 00:00:00 2007 Switzerland C1 434 FC Luzern England GB2 ... NaN NaN NaN NaN NaN 0.0 False 30.0 29.703553 (2005, 2010]
6130 12031 Eric Hassli 2011-03-01 00:00:00 2010 Switzerland C1 260 FC Zürich United States MLS1 ... NaN NaN NaN NaN NaN 0.0 False 29.0 28.665886 (2005, 2010]
6132 12031 Eric Hassli 2006-07-01 00:00:00 2006 Switzerland C1 257 FC St. Gallen France FR1 ... NaN NaN NaN NaN NaN 800000.0 False 25.0 24.665804 (2005, 2010]
6133 12031 Eric Hassli 2005-01-01 00:00:00 2004 Switzerland C1 61 Servette FC Switzerland C1 ... NaN NaN NaN NaN NaN 0.0 False 23.0 22.664394 (2000, 2005]
6134 12031 Eric Hassli 2004-07-01 00:00:00 2004 Switzerland C1 625 Neuchâtel Xamax Switzerland C1 ... NaN NaN NaN NaN NaN 1000000.0 False 23.0 22.664394 (2000, 2005]
6357 4277 Philippe Senderos 2003-07-01 00:00:00 2003 Switzerland C1 61 Servette FC England GB1 ... NaN NaN NaN https://twitter.com/Philsend4 https://www.philippesenderos.com 1500000.0 False 18.0 17.878533 (2000, 2005]
6358 4277 Philippe Senderos 2002-07-01 00:00:00 2002 Switzerland Other Switzerland 14179 Team Genève U17 Switzerland C1 ... NaN NaN NaN https://twitter.com/Philsend4 https://www.philippesenderos.com NaN False 17.0 16.879197 (2000, 2005]
7150 3900 Henri Camara 2001-07-01 00:00:00 2001 Switzerland C1 504 Grasshoppers France FR1 ... NaN NaN NaN NaN NaN 0.0 False 24.0 23.647303 (2000, 2005]
7151 3900 Henri Camara 2000-07-01 00:00:00 2000 Switzerland C1 625 Neuchâtel Xamax Switzerland C1 ... NaN NaN NaN NaN NaN 0.0 False 23.0 22.645229 (1995, 2000]
7188 4294 Marco Ambrosio 2005-01-01 00:00:00 2004 Switzerland C1 504 Grasshoppers Italy IT2 ... NaN NaN NaN NaN NaN NaN False 31.0 30.590635 (2000, 2005]
7454 4216 Florent Sinama-Pongolle 2015-07-01 00:00:00 2015 Switzerland Other Switzerland 527 Lausanne-Sport NaN NaN ... NaN NaN NaN https://twitter.com/sinamapongolle4 NaN NaN False 31.0 30.199114 (2010, 2015]
7505 34561 Johan Djourou 2003-07-14 00:00:00 2003 Switzerland Other Switzerland 1292 Etoile Carouge England GBJG ... NaN NaN NaN https://twitter.com/JohanDjourou https://www.johan-djourou.ch NaN False 16.0 15.953784 (2000, 2005]
7506 34561 Johan Djourou 2003-01-01 00:00:00 2002 Switzerland Other Switzerland 14195 Etoile Carouge FC Jugend Switzerland Other Switzerland ... NaN NaN NaN https://twitter.com/JohanDjourou https://www.johan-djourou.ch NaN False 15.0 14.954448 (2000, 2005]
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
290295 244463 Thierry Alain Mbognou 2013-01-30 00:00:00 2012 Switzerland Other Switzerland 2043 FC Schaan Austria Other Austria ... NaN NaN NaN NaN NaN NaN False 20.0 19.085950 (2010, 2015]
290475 64629 Miodrag Mitrović 2014-07-01 00:00:00 2014 Switzerland Other Switzerland 510 FC Chiasso Slovenia SL1 ... NaN NaN NaN NaN NaN 0.0 False 23.0 22.470003 (2010, 2015]
290476 64629 Miodrag Mitrović 2013-07-01 00:00:00 2013 Switzerland Other Switzerland 2411 FC Locarno Switzerland Other Switzerland ... NaN NaN NaN NaN NaN 0.0 False 22.0 21.470667 (2010, 2015]
290477 64629 Miodrag Mitrović 2010-07-01 00:00:00 2010 Switzerland Other Switzerland 15601 Locarno Jugend Switzerland Other Switzerland ... NaN NaN NaN NaN NaN NaN False 19.0 18.469921 (2005, 2010]
290573 174521 Marko Jakolic 2013-08-30 00:00:00 2013 Switzerland Other Switzerland 2144 FC Grenchen Slovenia Other Slovenia ... NaN NaN NaN NaN NaN 0.0 False 22.0 21.714340 (2010, 2015]
290632 203913 Fabian Lokaj 2016-01-01 00:00:00 2015 Switzerland Other Switzerland 32358 FC Köniz Slovenia SL1 ... NaN NaN NaN NaN NaN 0.0 False 19.0 18.357666 (2010, 2015]
290633 203913 Fabian Lokaj 2015-07-01 00:00:00 2015 Switzerland Other Switzerland 10400 Thun U21 Switzerland Other Switzerland ... NaN NaN NaN NaN NaN 0.0 False 19.0 18.357666 (2010, 2015]
290634 203913 Fabian Lokaj 2013-02-01 00:00:00 2012 Switzerland Other Switzerland 32283 BSC YB U17 Switzerland Other Switzerland ... NaN NaN NaN NaN NaN NaN False 16.0 15.356920 (2010, 2015]
290635 203913 Fabian Lokaj 2012-07-01 00:00:00 2012 Switzerland Other Switzerland 32282 BSC YB U16 Switzerland Other Switzerland ... NaN NaN NaN NaN NaN NaN False 16.0 15.356920 (2010, 2015]
291268 33522 Pablo Parmo 2006-01-01 00:00:00 2005 Switzerland Other Switzerland 2395 SC YF Juventus Chile Other Chile ... NaN NaN NaN NaN NaN 0.0 False 26.0 25.372184 (2000, 2005]
292719 31923 Toni Banduliev 2015-01-01 00:00:00 2014 Switzerland Other Switzerland 4345 Chur 97 NaN NaN ... NaN NaN NaN NaN NaN NaN False 34.0 33.232715 (2010, 2015]
292720 31923 Toni Banduliev 2014-10-01 00:00:00 2014 Switzerland Other Switzerland 26518 FC Ems Switzerland Other Switzerland ... NaN NaN NaN NaN NaN NaN False 34.0 33.232715 (2010, 2015]
292721 31923 Toni Banduliev 2011-07-01 00:00:00 2011 Switzerland Other Switzerland 4345 Chur 97 Switzerland Other Switzerland ... NaN NaN NaN NaN NaN 0.0 False 31.0 30.231969 (2010, 2015]
293024 40050 Tomi Saarelma 2014-01-01 00:00:00 2013 Switzerland Other Switzerland 2016 BSC Old Boys Finland FI1 ... NaN NaN NaN NaN NaN 0.0 False 25.0 24.088106 (2010, 2015]
293025 40050 Tomi Saarelma 2013-07-01 00:00:00 2013 Switzerland Other Switzerland 939 SR Delémont Switzerland Other Switzerland ... NaN NaN NaN NaN NaN NaN False 25.0 24.088106 (2010, 2015]
293026 40050 Tomi Saarelma 2012-07-01 00:00:00 2012 Switzerland Other Switzerland 747 FC Baden Switzerland Other Switzerland ... NaN NaN NaN NaN NaN 0.0 False 24.0 23.086032 (2010, 2015]
294075 39560 Sherif Ashraf 2014-03-26 00:00:00 2013 Switzerland Other Switzerland 2155 FC Biel-Bienne Egypt EGY1 ... NaN NaN NaN NaN NaN 10000.0 False 26.0 26.001903 (2010, 2015]
294923 177360 Moustapha Bacar 2012-07-01 00:00:00 2011 Switzerland Other Switzerland 5501 FC Zürich U21 NaN NaN ... NaN NaN NaN NaN NaN NaN False 23.0 22.031938 (2010, 2015]
295882 88277 Aissam Hamdaoui 2009-07-01 00:00:00 2009 Switzerland Other Switzerland 12424 Le Mont LS NaN NaN ... NaN NaN NaN NaN NaN NaN False 29.0 28.778141 (2005, 2010]
295883 88277 Aissam Hamdaoui 2008-09-01 00:00:00 2008 Switzerland Other Switzerland 12424 Le Mont LS NaN NaN ... NaN NaN NaN NaN NaN NaN False 28.0 27.776067 (2005, 2010]
297139 352460 Alexandre Nicolas 2005-07-01 00:00:00 2005 Switzerland Other Switzerland 37806 FC Marly Luxembourg LUX1 ... NaN NaN NaN NaN NaN 0.0 False 22.0 21.221517 (2000, 2005]
297369 3678 Diego Bortolozzo 2010-08-01 00:00:00 2010 Switzerland Other Switzerland 1287 FC Solothurn Germany Other Germany ... NaN NaN NaN NaN NaN 0.0 False 28.0 27.258602 (2005, 2010]
297686 55079 Florian Mateos 2012-07-01 00:00:00 2012 Switzerland Other Switzerland 5498 FC Serrières NaN NaN ... NaN NaN NaN NaN NaN 0.0 False 29.0 28.526253 (2010, 2015]
298137 60245 Landry Mandefu 2014-07-01 00:00:00 2013 Switzerland Other Switzerland 8463 Rapperswil-Jona Luxembourg Other Luxembourg ... NaN NaN NaN NaN NaN 0.0 False 27.0 26.544008 (2010, 2015]
298807 118136 Abdoul Diakité 2013-07-01 00:00:00 2013 Switzerland Other Switzerland 850 FC Wil 1900 NaN NaN ... NaN NaN NaN NaN http://www.abdouldiakite.skynetblogs.be NaN False 27.0 26.973860 (2010, 2015]
298816 138116 Mickael Regulant 2013-07-01 00:00:00 2013 Switzerland Other Switzerland 8463 Rapperswil-Jona NaN NaN ... NaN NaN NaN NaN NaN NaN False 23.0 22.713677 (2010, 2015]
300233 74748 Jerry Prempeh 2012-07-01 00:00:00 2012 Switzerland Other Switzerland 1288 Team Fribourg Luxembourg LUX1 ... NaN NaN NaN NaN NaN 0.0 False 24.0 23.006633 (2010, 2015]
300577 43466 Kevin Lefranc 2013-07-01 00:00:00 2013 Switzerland Other Switzerland 939 SR Delémont Luxembourg LUX1 ... NaN NaN NaN NaN NaN NaN False 27.0 26.839702 (2010, 2015]
300581 43466 Kevin Lefranc 2009-07-01 00:00:00 2009 Switzerland Other Switzerland 5259 FC Baulmes Belgium Other Belgium ... NaN NaN NaN NaN NaN NaN False 23.0 22.839620 (2005, 2010]
302429 57507 Bruce Abdoulaye 2005-01-01 00:00:00 2004 Switzerland Other Switzerland 527 Lausanne-Sport France Other France ... NaN NaN NaN NaN NaN 0.0 False 22.0 21.714340 (2000, 2005]

5996 rows × 59 columns


In [6]:
transfers[(transfers.season==2011)&(transfers.toCountry!=transfers.fromCountry)].count()


Out[6]:
id                             11299
playerName                     11299
date                           11289
season                         11299
fromCountry                    11299
fromLeague                      9518
fromTeamId                     11299
fromTeamName                   11299
toCountry                      11299
toLeague                        7689
toTeamId                       11299
toTeamName                     11299
mv                              8517
fee                            11299
displayName                    11299
nameInHomeCountry               5570
dateOfBirth                    11280
placeOfBirth                    9596
countryOfBirth                  9572
Age                            11260
Height                         10637
Nationality                    11298
nationality2                    2583
positionGroup                  11297
Position                        9478
mainPosition                   10402
sidePosition                    5319
Foot                            9609
nationalTeamId                 11299
intlCaps                       11299
intlGoals                      11299
playersAgent                    5436
playersAgentId                 11299
currentClub                    11299
currentClubId                  11299
inTheTeamSince                 11162
contractUntil                   3290
onLoanFrom                       259
onLoanFromClubId                 259
contractThereUntil               158
2ndClub                           27
2ndClubId                         27
completeName                    1008
contractOption                   203
dateOfLastContractExtension      511
Glove                              2
Outfitter                        178
shoeModel                         43
shoeSize                          14
dayOfDeath                        20
facebook                         145
instagram                        109
twitter                          270
website                          332
feeValue                        4971
isLoan                         11299
age                            11280
ageFloat                       11280
period                         11299
dtype: int64

In [4]:
def top(df):
    return df[df.toLeague.notnull()].sort_values('mv',ascending=False).drop_duplicates('id')[:5][['id','displayName','mv','toTeamName','toLeague']]

nonloans.groupby('Nationality').apply(top)


Out[4]:
id displayName mv toTeamName toLeague
Nationality
Afghanistan 99629 111182 Shabir Isoufi 200000.0 Telstar NL2
213570 262104 Faysal Shayesteh 150000.0 Songkhla United Other Thailand
98510 84280 Qays Shayesteh 125000.0 VV DETO Other Netherlands
184887 45836 Djelaludin Sharityar 125000.0 Manama Club Other Bahrain
127517 155050 Sharif Mukhammad 25000.0 Anzhi RU1
Albania 14385 12149 Lorik Cana 14000000.0 Sunderland GB1
66356 200056 Elseid Hysaj 4500000.0 SSC Napoli IT1
147926 32704 Shkelzen Gashi 3500000.0 Colorado MLS1
55713 6075 Erjon Bogdani 3250000.0 Chievo Verona IT1
114541 43297 Debatik Curri 2500000.0 Genclerbirligi TR1
Algeria 64420 111039 Ishak Belfodil 10000000.0 Inter IT1
10886 38074 Madjid Bougherra 6500000.0 Lekhwiya QSL
46211 25976 Karim Ziani 6500000.0 VfL Wolfsburg L1
71883 20903 Rafik Djebbour 6000000.0 Nottm Forest GB2
13319 23892 Nadir Belhadj 5500000.0 Al-Sadd QSL
Andorra 158950 44106 Antoni Lima NaN Ibiza Eivissa Other Spain
Angola 86039 51191 Djalma 2900000.0 FC Porto PO1
83814 37947 Mateus 2500000.0 Arouca PO1
12817 64484 Manucho 2300000.0 Real Valladolid ES1
138444 38813 Flávio 2000000.0 Lierse SK BE1
37925 2712 Nando Rafael 1750000.0 Bor. M'gladbach L1
Antigua and Barbuda 5223 28491 Dexter Blackstock 2000000.0 Nottm Forest GB2
10237 38094 Lee Peltier 1500000.0 Cardiff GB2
8751 14041 Mikele Leigertwood 1200000.0 QPR GB2
201700 132236 Josh Parker 400000.0 Red Star SER1
9333 39038 James Walker 300000.0 Gillingham FC GB3
Argentina 18104 45320 Ángel Di María 50000000.0 Paris SG FR1
16037 26399 Sergio Agüero 36000000.0 Manchester City GB1
61570 50570 Ezequiel Lavezzi 30000000.0 Paris SG FR1
26682 39153 Gonzalo Higuaín 30000000.0 SSC Napoli IT1
... ... ... ... ... ... ...
Uruguay 15221 44352 Luis Suárez 52000000.0 FC Barcelona ES1
33112 54859 Álvaro Pereira 16000000.0 Inter IT1
17137 13829 Diego Lugano 14000000.0 Paris SG FR1
16728 123742 Gastón Ramírez 13500000.0 Southampton GB1
Uzbekistan 126691 63606 Odil Akhmedov 6000000.0 FK Krasnodar RU1
152633 25823 Vitali Denisov 2000000.0 Loko Moscow RU1
126731 106632 Sanjar Tursunov 1500000.0 Alania RU2
121952 15578 Aleksandr Geynrikh 1400000.0 Aktobe KAS1
148438 9798 Maksim Shatskikh 1000000.0 Lok. Astana KAS1
Venezuela 18596 80197 José Salomón Rondón 15000000.0 West Brom GB1
25278 26063 Juan Arango 7000000.0 Bor. M'gladbach L1
17388 35548 Fernando Amorebieta 6000000.0 Fulham FC GB1
117492 72567 Ronald Vargas 5000000.0 RSC Anderlecht BE1
28946 53309 Jeffrén 5000000.0 Sporting CP PO1
Vietnam 87004 64640 Cong Vinh Le 300000.0 Bec. Binh Duong Other Vietnam
Wales 12597 39381 Gareth Bale 65000000.0 Real Madrid ES1
2116 3297 Craig Bellamy 12000000.0 West Ham GB1
4194 4056 Simon Davies 5500000.0 Everton GB1
16607 192765 Ben Davies 5500000.0 Spurs GB1
8505 12707 Robert Earnshaw 5300000.0 Norwich GB2
Zambia 16232 55709 Emmanuel Mayuka 6000000.0 Southampton GB1
74566 25118 Jacob Mulenga 2500000.0 Adana Demirspor TR2
77895 82324 Stoppila Sunzu 2000000.0 SH Shenhua CSL
168403 46005 Christopher Katongo 1500000.0 AO Xanthi GR1
8936 32515 Collins Mbesuma 1500000.0 Bursaspor TR1
Zimbabwe 9744 12063 Benjani 5000000.0 Blackburn GB1
126653 58467 Musawengosi Mguni 1300000.0 Terek Grozny RU1
47802 120785 Knowledge Musona 1000000.0 KV Oostende BE1
217055 83882 Quincy Antipas 900000.0 Hobro IK DK1
139105 146721 Nyasha Mushekwi 800000.0 DL Yifang Other China

810 rows × 5 columns


In [76]:
def topClubs(df,direction='to',field='id',agg=('count','count'),ascending=False):
    teamIdTable=DataFrame({'teamName':teamIdMap})
    teamIdTable.index.name= direction+'TeamId'
    s = df.groupby([direction+'TeamId'])[[field]] \
    .agg(agg[1]).join(teamIdTable).sort_values(field,ascending=ascending) \
    .reset_index(level=-1)[['teamName',field]]
    s['cumulative %']=(s[field].cumsum())/(s[field].sum())
    s=s[s['cumulative %'].shift(1).fillna(0)<2/3.]
    s=s[s[field]>0]
    return s.rename(columns={field:(agg[0] + ' of '+ field),('teamName'):(direction +' club')})

t=nonloans[(nonloans['fromCountry']!=nonloans['toCountry'])&(nonloans.season>2000)]

def countNonZero(l):
    return l[l>0].count()

def countIsZero(l):
    return l[l==0].count()


def createTable(tt,direction,field,agg,ascending=False):
    o=tt.groupby([direction+'Country','period']).apply(topClubs,direction=direction,field=field,agg=agg,ascending=ascending).unstack(level=1).reorder_levels(axis=1,order=[1,0]).sort_index(axis=1,level=0)
    #ew = pd.ExcelWriter('../data/output/'+direction+'_' +field + '_' + agg[0] + '.xls', encoding='utf-8')
    #o.to_excel(ew)
    #ew.save()
    return o

#createTable(t[t.fromLeague.isin(leagueList)],'from','feeValue', ('sum','sum'), False)
#createTable(t[t.toLeague.isin(leagueList)],'to','feeValue', ('sum','sum'), False)
#createTable(t[t.toLeague.isin(leagueList)],'to','id', ('count','count'), False)
#createTable(t[t.fromLeague.isin(leagueList)],'from','id', ('count','count'), False)


createTable(t[(~t.fromCountry.isin(uefa))&t.toLeague.isin(leagueList)&t.toCountry.isin(uefa)],'to','id', ('count','count'), False)


Out[76]:
period (2000, 2005] (2005, 2010] (2010, 2015]
to club count of id cumulative % to club count of id cumulative % to club count of id cumulative %
toCountry
Austria 0 RB Salzburg 6.0 0.222222 SCR Altach 8.0 0.210526 RB Salzburg 15.0 0.333333
1 Admira Wacker 5.0 0.407407 RB Salzburg 6.0 0.368421 Sturm Graz 6.0 0.466667
2 Austria Vienna 3.0 0.518519 LASK 5.0 0.500000 Wiener Neustadt 5.0 0.577778
3 Bregenz 3.0 0.629630 FC Wacker 4.0 0.605263 SV Kapfenberg 4.0 0.666667
4 Sturm Graz 2.0 0.703704 Austria Kärnten 3.0 0.684211 None NaN NaN
Azerbaijan 0 Xäzär Länkäran 3.0 0.428571 Xäzär Länkäran 9.0 0.281250 Ravan Baku 18.0 0.178218
1 Neftchi Baku 2.0 0.714286 Inter Baku 8.0 0.531250 AZAL 15.0 0.326733
2 None NaN NaN Neftchi Baku 7.0 0.750000 Neftchi Baku 12.0 0.445545
3 None NaN NaN None NaN NaN Kapaz Ganja 9.0 0.534653
4 None NaN NaN None NaN NaN Xäzär Länkäran 9.0 0.623762
5 None NaN NaN None NaN NaN Qarabag Agdam 7.0 0.693069
Belgium 0 KSK Beveren 28.0 0.222222 Beerschot AC 13.0 0.105691 Lierse SK 16.0 0.136752
1 KSC Lokeren 20.0 0.380952 Standard Liège 13.0 0.211382 KVC Westerlo 11.0 0.230769
2 Beerschot AC 18.0 0.523810 KAA Gent 12.0 0.308943 Standard Liège 10.0 0.316239
3 AA La Louviere 7.0 0.579365 RSC Anderlecht 9.0 0.382114 Club Brugge 10.0 0.401709
4 Standard Liège 6.0 0.626984 KSC Lokeren 9.0 0.455285 KSC Lokeren 8.0 0.470085
5 RSC Charleroi 6.0 0.674603 Lierse SK 8.0 0.520325 RSC Anderlecht 8.0 0.538462
6 None NaN NaN KVC Westerlo 7.0 0.577236 KV Mechelen 7.0 0.598291
7 None NaN NaN Club Brugge 5.0 0.617886 Waasl.-Beveren 7.0 0.658120
8 None NaN NaN RSC Charleroi 5.0 0.658537 Cercle Brugge 5.0 0.700855
9 None NaN NaN KV Mechelen 5.0 0.699187 None NaN NaN
Bosnia-Herzegovina 0 Zeljeznicar 7.0 0.368421 Siroki Brijeg 15.0 0.154639 Travnik 15.0 0.091463
1 Siroki Brijeg 5.0 0.631579 Zeljeznicar 12.0 0.278351 FK Sarajevo 14.0 0.176829
2 FK Sarajevo 3.0 0.789474 Olimp. Sarajevo 8.0 0.360825 Slavija S. 14.0 0.262195
3 None NaN NaN Sloboda Tuzla 6.0 0.422680 Zeljeznicar 12.0 0.335366
4 None NaN NaN Zvijezda G. 6.0 0.484536 Olimp. Sarajevo 12.0 0.408537
5 None NaN NaN FK Laktasi 6.0 0.546392 Zvijezda G. 10.0 0.469512
6 None NaN NaN Zrinjski Mostar 6.0 0.608247 Celik Zenica 9.0 0.524390
7 None NaN NaN Leotar Trebinje 5.0 0.659794 Mladost Obarska 9.0 0.579268
8 None NaN NaN B. Banja Luka 5.0 0.711340 B. Banja Luka 8.0 0.628049
... ... ... ... ... ... ... ... ... ... ...
Sweden 6 Örgryte 2.0 0.689655 Mjällby AIF 4.0 0.642857 Djurgardens IF 5.0 0.542169
7 None NaN NaN Djurgardens IF 4.0 0.700000 Gefle IF 5.0 0.602410
8 None NaN NaN None NaN NaN Syrianska FC 5.0 0.662651
9 None NaN NaN None NaN NaN Örebro SK 4.0 0.710843
Switzerland 0 Neuchâtel Xamax 12.0 0.155844 FC Sion 12.0 0.136364 FC Sion 13.0 0.191176
1 Servette FC 10.0 0.285714 BSC Young Boys 11.0 0.261364 Grasshoppers 11.0 0.352941
2 FC St. Gallen 7.0 0.376623 FC St. Gallen 10.0 0.375000 FC Basel 10.0 0.500000
3 Grasshoppers 7.0 0.467532 FC Thun 8.0 0.465909 FC Zürich 8.0 0.617647
4 BSC Young Boys 6.0 0.545455 FC Basel 7.0 0.545455 Lausanne-Sport 6.0 0.705882
5 FC Thun 6.0 0.623377 FC Zürich 7.0 0.625000 None NaN NaN
6 FC Basel 5.0 0.688312 Neuchâtel Xamax 7.0 0.704545 None NaN NaN
Turkey 0 Ankaragücü 11.0 0.114583 Bursaspor 14.0 0.116667 Gaziantepspor 9.0 0.095745
1 Samsunspor 9.0 0.208333 Gaziantepspor 9.0 0.191667 Mersin IY 9.0 0.191489
2 Trabzonspor 8.0 0.291667 Ankaragücü 9.0 0.266667 Sivasspor 8.0 0.276596
3 Gaziantepspor 7.0 0.364583 Genclerbirligi 8.0 0.333333 Antalyaspor 7.0 0.351064
4 Fenerbahce 7.0 0.437500 Denizlispor 7.0 0.391667 Elazigspor 6.0 0.414894
5 Rizespor 6.0 0.500000 Rizespor 7.0 0.450000 Akhisarspor 6.0 0.478723
6 Osmanlispor 5.0 0.552083 Konyaspor 6.0 0.500000 Kasimpasa 5.0 0.531915
7 Konyaspor 5.0 0.604167 Sivasspor 6.0 0.550000 K. Erciyesspor 5.0 0.585106
8 Malatyaspor 5.0 0.656250 Fenerbahce 6.0 0.600000 Genclerbirligi 5.0 0.638298
9 A.Sebatspor 4.0 0.697917 Manisaspor 5.0 0.641667 Galatasaray 4.0 0.680851
10 None NaN NaN Kayserispor 5.0 0.683333 None NaN NaN
Ukraine 0 Dynamo Kyiv 9.0 0.150000 Chornomorets 15.0 0.159574 Metalist 16.0 0.123077
1 SK Tavriya 8.0 0.283333 Dynamo Kyiv 11.0 0.276596 Volyn Lutsk 14.0 0.230769
2 Metalurg D. 8.0 0.416667 Metalist 10.0 0.382979 Metalurg Z. 12.0 0.323077
3 Shakhtar D. 7.0 0.533333 Metalurg Z. 8.0 0.468085 Goverla 11.0 0.407692
4 Metalurg Z. 5.0 0.616667 Zorya Lugansk 8.0 0.553191 Chornomorets 11.0 0.492308
5 Volyn Lutsk 4.0 0.683333 Goverla 6.0 0.617021 Shakhtar D. 9.0 0.561538
6 None NaN NaN Shakhtar D. 6.0 0.680851 Zorya Lugansk 9.0 0.630769
7 None NaN NaN None NaN NaN SK Tavriya 7.0 0.684615

318 rows × 9 columns


In [83]:
t=transfers
t[(t.fromCountry=='Portugal')&(t.toCountry=='Greece')&(t.facebook.notnull()|t.instagram.notnull()|t.twitter.notnull()|t.website.notnull())]


Out[83]:
id playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... dayOfDeath facebook instagram twitter website feeValue isLoan age ageFloat period
79041 45889 Bruno Pereirinha 2011-01-01 00:00:00 2010 Portugal PO1 336 Sporting CP Greece GR1 ... NaN https://www.facebook.com/pages/Bruno-Pereirinh... https://instagram.com/brunopereirinha17# https://twitter.com/Brun0Pereirinha NaN 0.0 True 22.0 21.834808 (2005, 2010]
83618 5413 Jaouad Zairi 2007-07-01 00:00:00 2007 Portugal PO1 2503 Boavista Greece GR1 ... NaN NaN NaN NaN https://www.jaouadzairi.net 0.0 False 25.0 24.709611 (2005, 2010]
91780 8518 Freddy Adu 2010-01-06 00:00:00 2009 Portugal PO1 294 Benfica Greece GR1 ... NaN NaN https://instagram.com/freddy_adu https://twitter.com/FreddyAdu https://www.freddyadu.com 0.0 True 20.0 19.584249 (2005, 2010]
103126 34013 Bruno Fogaça 2006-08-01 00:00:00 2006 Portugal PO1 4814 Naval Greece GR1 ... NaN NaN NaN NaN https://www.brunofogaca.com 100000.0 False 25.0 24.140126 (2005, 2010]
105074 80599 David Addy 2011-08-15 00:00:00 2011 Portugal PO1 720 FC Porto Greece GR1 ... NaN NaN NaN NaN https://www.davidaddy.com 0.0 True 21.0 20.860113 (2010, 2015]
193498 34013 Bruno Fogaça 2006-08-01 00:00:00 2006 Portugal PO1 4814 Naval Greece GR1 ... NaN NaN NaN NaN https://www.brunofogaca.com 100000.0 False 25.0 24.140126 (2005, 2010]

6 rows × 59 columns


In [29]:
agentIdTable=DataFrame({'playersAgent':agentIdMap})
agentIdTable.index.name='playersAgentId'

In [221]:
ew = pd.ExcelWriter('../data/reference/countries.xls', encoding='utf-8')
DataFrame({'country':pd.concat([transfers.fromCountry,transfers.toCountry,transfers.Nationality,transfers.nationality2]).drop_duplicates().sort_values()}).to_excel(ew)
ew.save()

In [40]:
uefa=countryInfo[countryInfo.federation=='UEFA'].index
caf=countryInfo[countryInfo.federation=='CAF'].index
concacaf=countryInfo[countryInfo.federation=='CONCACAF'].index
concacaf_no_uscan=countryInfo[countryInfo.federation=='CONCACAF'].drop(['United States','Canada']).index
conmebol=countryInfo[countryInfo.federation=='CONMEBOL'].index
afc=countryInfo[countryInfo.federation=='AFC'].index
afc_no_anzac=countryInfo[countryInfo.federation=='AFC'].drop(['Australia','New Zealand']).index


t=transfers[(transfers.fromCountry.str.contains('Jamaica'))&(transfers.toCountry.isin(uefa))&(transfers.fromCountry.notnull())&(transfers.toCountry.notnull())]
t=transfers[(transfers.fromCountry.isin(conmebol))&(transfers.toCountry.isin(uefa))&(transfers.fromCountry.notnull())&(transfers.toCountry.notnull())]

#
t=t[t.feeValue==0]
#t.groupby('fromCountry').agg({'id':'count','feeValue':'sum','season':'median'}).sort_values('id',ascending=False).id#.plot.pie()
t.groupby('toCountry').agg({'id':'count','feeValue':'sum','season':'median'}).sort_values('id',ascending=False).id#.plot.pie()
#t[t.toCountry=='Norway']


Out[40]:
toCountry
Portugal              453
Greece                224
Spain                 179
Italy                 142
Romania                79
France                 73
Switzerland            63
Turkey                 61
Belgium                61
Cyprus                 58
Germany                52
Sweden                 47
Poland                 47
Hungary                45
Bulgaria               33
England                30
Netherlands            29
Israel                 28
Ukraine                28
Austria                24
Russia                 21
Croatia                20
Finland                20
Malta                  20
Slovakia               18
Norway                 15
Azerbaijan             15
Denmark                13
Serbia                 11
Kazakhstan             10
Scotland                9
Lithuania               7
Czech Republic          7
Slovenia                6
Luxembourg              4
Moldova                 4
Armenia                 3
Albania                 3
Bosnia-Herzegovina      3
Belarus                 2
Ireland                 2
Montenegro              1
Macedonia               1
Estonia                 1
Andorra                 1
Iceland                 1
Georgia                 1
Name: id, dtype: int64

In [175]:
t=nonloans
t=t[t.season>=2000]
t=t[t.toLeague!='GB1']
t.groupby('season').sum()['feeValue'].plot.line()


Out[175]:
<matplotlib.axes._subplots.AxesSubplot at 0x110fa9510>

In [57]:
transfers.columns


Out[57]:
Index([u'id', u'playerName', u'date', u'season', u'fromCountry', u'fromLeague',
       u'fromTeamId', u'fromTeamName', u'toCountry', u'toLeague', u'toTeamId',
       u'toTeamName', u'mv', u'fee', u'displayName', u'nameInHomeCountry',
       u'dateOfBirth', u'placeOfBirth', u'countryOfBirth', u'Age', u'Height',
       u'Nationality', u'nationality2', u'positionGroup', u'Position',
       u'mainPosition', u'sidePosition', u'Foot', u'nationalTeamId',
       u'intlCaps', u'intlGoals', u'playersAgent', u'playersAgentId',
       u'currentClub', u'currentClubId', u'inTheTeamSince', u'contractUntil',
       u'onLoanFrom', u'onLoanFromClubId', u'contractThereUntil', u'2ndClub',
       u'2ndClubId', u'completeName', u'contractOption',
       u'dateOfLastContractExtension', u'Glove', u'Outfitter', u'shoeModel',
       u'shoeSize', u'dayOfDeath', u'facebook', u'instagram', u'twitter',
       u'website', u'feeValue', u'isLoan', u'age', u'ageFloat', u'period'],
      dtype='object')

In [44]:
t=transfers
z=t.groupby('id').apply(lambda x:max(x.feeValue.sort_values()))

In [58]:
tt=t.merge(DataFrame({'maxFee':z}),left_on='id',right_index=True,how='left')
tt=tt.drop_duplicates('id')[['id','playerName','intlCaps','intlGoals','countryOfBirth','Nationality','maxFee','Age','currentClub']]

tt[(tt.intlCaps==0)&(tt.maxFee>0)].sort_values('maxFee',ascending=False)


Out[58]:
id playerName intlCaps intlGoals countryOfBirth Nationality maxFee Age currentClub
182008 66515 Alex Teixeira 0 0 Brazil Brazil 50000000.0 26.0 Jiangsu Suning
37399 59344 Asier Illarramendi 0 0 Spain Spain 32000000.0 26.0 Real Sociedad
14274 26456 Mauro Zárate 0 0 Argentina Argentina 20200000.0 29.0 ACF Fiorentina
182653 76028 Taison 0 0 Brazil Brazil 15240000.0 28.0 Shakhtar Donetsk
24173 149498 Gabriel Paulista 0 0 Brazil Brazil 15000000.0 25.0 Arsenal FC
40560 68821 Keirrison 0 0 Brazil Brazil 14000000.0 27.0 Londrina Esporte Clube PR
7998 12127 Michael Turner 0 0 England England 13600000.0 32.0 Sheffield Wednesday
24503 110858 Benik Afobe 0 0 England Congo DR 13300000.0 23.0 AFC Bournemouth
53074 52947 Breno 0 0 Brazil Brazil 12000000.0 26.0 São Paulo Futebol Clube
24671 253677 Tyrone Mings 0 0 England England 11300000.0 23.0 AFC Bournemouth
28204 7983 Cani 0 0 Spain Spain 11000000.0 34.0 Deportivo de La Coruña
37978 33218 Luca Cigarini 0 0 Italy Italy 11000000.0 29.0 Atalanta BC
95648 258254 Jemerson 0 0 Brazil Brazil 11000000.0 23.0 AS Monaco
23037 72047 Iago Aspas 0 0 Spain Spain 10800000.0 28.0 Celta de Vigo
3817 3704 Corrado Grabbi 0 0 Italy Italy 10700000.0 40.0 End of career
69817 30638 Sergio Floccari 0 0 Italy Italy 10500000.0 34.0 Bologna FC 1909
23752 54890 Leonardo Ulloa 0 0 Argentina Argentina 10120000.0 29.0 Leicester City
78559 122582 Juan Quintero 0 0 Colombia Colombia 10000000.0 23.0 FC Porto
66102 6020 Francesco Tavano 0 0 Italy Italy 10000000.0 37.0 US Avellino 1912
38888 44373 Guilherme Siqueira 0 0 Brazil Brazil 10000000.0 30.0 Valencia CF
16577 16576 Carlos Cuéllar 0 0 Spain Spain 10000000.0 34.0 UD Almería
81715 96454 Maxime Lestienne 0 0 Belgium Belgium 10000000.0 23.0 PSV Eindhoven
87451 12151 Reinaldo 0 0 Brazil Brazil 10000000.0 37.0 Boavista Sport Club (RJ)
25547 8754 Émerson 0 0 Brazil Brazil 9600000.0 44.0 End of career
24406 104124 Michail Antonio 0 0 England England 9500000.0 26.0 West Ham United
56278 45672 Kevin Trapp 0 0 Germany Germany 9500000.0 25.0 Paris Saint-Germain
41598 159142 Aderlan Santos 0 0 Brazil Brazil 9500000.0 27.0 Valencia CF
10037 35413 Lewis Grabban 0 0 England Jamaica 9350000.0 28.0 AFC Bournemouth
195366 68711 Diogo 0 0 Brazil Brazil 9000000.0 29.0 Buriram United
95218 184672 Guido Carrillo 0 0 Argentina Argentina 9000000.0 24.0 AS Monaco
... ... ... ... ... ... ... ... ... ...
212843 378746 Laurentiu Corbu 0 0 NaN Romania 5000.0 22.0 Dinamo Bukarest
208306 105584 Souleymane Keita 0 0 Senegal Senegal 5000.0 28.0 C.S. National Sebis
245430 39305 Anderson 0 0 Brazil Brazil 5000.0 36.0 Sociedade Esportiva Itapirense (SP)
213424 415457 Andrei Burlacu 0 0 Romania Romania 5000.0 19.0 CS U Craiova
285198 100164 Igor Migalevskyi 0 0 UDSSR Ukraine 5000.0 31.0 Atomic Selects Toronto
339136 120662 Dinis De Sousa 0 0 NaN Luxembourg 5000.0 41.0 End of career
211912 295887 Florentin Pham-Huy 0 0 Romania Romania 5000.0 19.0 Academia Clinceni
288353 218426 Marcin Trojanowski 0 0 Poland Poland 5000.0 26.0 Pelikan Niechanowo
203178 46520 Marian Constantinescu 0 0 Romania Romania 5000.0 34.0 Concordia Chiajna
242563 86894 Pavel Stanev 0 0 NaN Bulgaria 5000.0 29.0 Kaspiy Aktau
304254 103393 Marco Kofler 0 0 Austria Austria 5000.0 27.0 FC Hansa Rostock
302295 40711 Rudolf Durkovic 0 0 NaN Austria 4000.0 27.0 WSC Hertha Wels
222625 77703 Josip Golubar 0 0 Jugoslawien (SFR) Croatia 4000.0 31.0 NK Zavrc
303700 80214 Hrvoje Jakovljevic 0 0 Jugoslawien (SFR) Croatia 4000.0 25.0 VST Völkermarkt
104667 77813 Carciano 0 0 Brazil Brazil 4000.0 35.0 Rio Branco Football Club (AC)
269127 70725 Nathan Fisher 0 0 England England 4000.0 26.0 Unknown
291290 141115 Ciprian Claudiu Binder 0 0 Romania Romania 4000.0 40.0 End of career
315303 203373 Terence Agius 0 0 NaN Malta 3000.0 22.0 Pembroke Athleta FC
229394 60466 Zarko Karamatic 0 0 Jugoslawien (SFR) Serbia 3000.0 28.0 FK Trepca
220128 27856 Drazen Govic 0 0 Jugoslawien (SFR) Croatia 3000.0 35.0 HNK Sibenik
283690 27144 Marcin Folc 0 0 Poland Poland 3000.0 34.0 Gornik Walbrzych
313398 236769 Jeffrey Farrugia 0 0 NaN Malta 2000.0 27.0 Senglea Athletic FC
289843 9703 Stipe Matic 0 0 NaN Croatia 2000.0 37.0 FC Oberwallis Naters
222132 113696 Vedran Jerkovic 0 0 Jugoslawien (SFR) Croatia 2000.0 24.0 SC Borussia Fulda
287672 235795 Damian Buras 0 0 Poland Poland 2000.0 22.0 Wisla Krakow II
70145 54920 Mirko Velardi 0 0 Italy Italy 1000.0 28.0 Derthona FBC
63771 5858 Paolo Cannavaro 0 0 Italy Italy 1000.0 34.0 US Sassuolo
288084 225894 Lukasz Zeglen 0 0 Poland Poland 1000.0 21.0 Stal Mielec
79802 147876 Abdou Doumbia 0 0 France France 1000.0 25.0 US Lecce
287610 257244 Adam Deja 0 0 Poland Poland 1000.0 22.0 Podbeskidzie Bielsko-Biala

3893 rows × 9 columns


In [66]:
def getMvIncreases(t):
    return t[(t.mv>t.mv.shift(1))&(t.mv.notnull())&(t.mv.shift(1).notnull())]
    
def getFeeIncreases(t):
    return t[(t.mv>t.feeValue.shift(1))&(t.feeValue.notnull())&(t.feeValue.shift(1).notnull())]

def getMvDecreases(t):
    return t[(t.mv<t.mv.shift(1))&(t.mv.notnull())&(t.mv.shift(1).notnull())]

def getFeeDecreases(t):
    return t[(t.mv<t.feeValue.shift(1))&(t.feeValue.notnull())&(t.feeValue.shift(1).notnull())]

    
tt=nonloans.groupby('id').apply(getMvIncreases)

In [10]:
import dateutil
t=nonloans[nonloans['id']==110858]
t.date.shift(1)


Out[10]:
18527                    NaN
18528    2016-01-10 00:00:00
18529    2015-01-14 00:00:00
Name: date, dtype: object

In [27]:
nonloans[nonloans['id']==8806].feeValue.fillna(method='bfill').iloc[::-1].diff().iloc[::-1]


Out[27]:
6247    -1000000.0
6248    30800000.0
6249           NaN
Name: feeValue, dtype: float64

In [43]:
transfers[transfers.intlCaps==0]


Out[43]:
id playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... dayOfDeath facebook instagram twitter website feeValue isLoan age ageFloat period
46 4101 Richard Rufus 2004-07-01 00:00:00 2004 England GB1 358 Charlton NaN NaN ... NaN NaN NaN NaN NaN NaN False 29.0 28.969794 (2000, 2005]
47 4101 Richard Rufus 1995-07-01 00:00:00 1995 England GBJG 6932 Charlton U18 England Other England ... NaN NaN NaN NaN NaN NaN False 20.0 19.970294 NaN
48 4102 Gary Rowett 2004-07-01 00:00:00 2004 England GB1 358 Charlton NaN NaN ... NaN NaN NaN NaN NaN NaN False 30.0 29.824021 (2000, 2005]
49 4102 Gary Rowett 2002-07-01 00:00:00 2002 England Other England 1003 Leicester England GB1 ... NaN NaN NaN NaN NaN 5250000.0 False 28.0 27.825349 (2000, 2005]
50 4102 Gary Rowett 2000-07-01 00:00:00 2000 England Other England 337 Birmingham England GB1 ... NaN NaN NaN NaN NaN 4500000.0 False 26.0 25.823939 (1995, 2000]
51 4102 Gary Rowett 1998-07-01 00:00:00 1998 England GB1 22 Derby England Other England ... NaN NaN NaN NaN NaN 1400000.0 False 24.0 23.825267 (1995, 2000]
52 4102 Gary Rowett 1996-07-01 00:00:00 1996 England GB1 29 Everton England GB1 ... NaN NaN NaN NaN NaN 420000.0 False 22.0 21.823857 (1995, 2000]
53 4102 Gary Rowett 1995-07-01 00:00:00 1995 England Other England 986 Cambridge Utd. England GB1 ... NaN NaN NaN NaN NaN 280000.0 False 21.0 20.824521 NaN
54 4103 Jonathan Fortune 2013-07-01 00:00:00 2013 England GB4 3696 Dag & Red FC NaN NaN ... NaN NaN NaN NaN NaN NaN False 33.0 32.359323 (2010, 2015]
55 4103 Jonathan Fortune 2013-03-28 00:00:00 2012 England Other England 29512 Chatham Town FC England GB4 ... NaN NaN NaN NaN NaN 0.0 False 32.0 31.357249 (2010, 2015]
56 4103 Jonathan Fortune 2013-02-08 00:00:00 2012 England GB4 2804 Barnet England Other England ... NaN NaN NaN NaN NaN 0.0 False 32.0 31.357249 (2010, 2015]
57 4103 Jonathan Fortune 2012-07-26 00:00:00 2012 England GB4 6699 Exeter City England GB4 ... NaN NaN NaN NaN NaN 0.0 False 32.0 31.357249 (2010, 2015]
58 4103 Jonathan Fortune 2012-03-09 00:00:00 2011 NaN NaN 515 Unattached England GB3 ... NaN NaN NaN NaN NaN NaN False 31.0 30.357913 (2010, 2015]
59 4103 Jonathan Fortune 2011-07-01 00:00:00 2011 England GB3 358 Charlton NaN NaN ... NaN NaN NaN NaN NaN NaN False 31.0 30.357913 (2010, 2015]
60 4103 Jonathan Fortune 2010-08-31 00:00:00 2010 England GB2 350 Sheffield Utd. England GB3 ... NaN NaN NaN NaN NaN 0.0 False 30.0 29.358577 (2005, 2010]
61 4103 Jonathan Fortune 2009-09-20 00:00:00 2009 England GB3 358 Charlton England GB2 ... NaN NaN NaN NaN NaN 0.0 False 29.0 28.359241 (2005, 2010]
62 4103 Jonathan Fortune 2007-03-09 00:00:00 2006 England GB1 358 Charlton England GB2 ... NaN NaN NaN NaN NaN 0.0 True 26.0 25.358495 (2005, 2010]
63 4103 Jonathan Fortune 2007-01-31 00:00:00 2006 England GB1 358 Charlton England GB2 ... NaN NaN NaN NaN NaN 0.0 True 26.0 25.358495 (2005, 2010]
64 4103 Jonathan Fortune 2000-08-30 00:00:00 2000 England GB1 358 Charlton England Other England ... NaN NaN NaN NaN NaN 0.0 True 20.0 19.357003 (1995, 2000]
65 4103 Jonathan Fortune 2000-02-17 00:00:00 1999 England Other England 358 Charlton England Other England ... NaN NaN NaN NaN NaN 0.0 True 19.0 18.357666 (1995, 2000]
66 4103 Jonathan Fortune 1998-08-01 00:00:00 1998 England GBJG 6932 Charlton U18 England GB1 ... NaN NaN NaN NaN NaN NaN False 18.0 17.358330 (1995, 2000]
74 4110 Scott Bevan 2014-07-01 00:00:00 2014 England Other England 2794 Havant & Water. NaN NaN ... NaN NaN NaN NaN NaN NaN False 35.0 34.295023 (2010, 2015]
75 4110 Scott Bevan 2013-07-13 00:00:00 2013 England GB4 2455 Bristol Rovers England Other England ... NaN NaN NaN NaN NaN 0.0 False 34.0 33.295687 (2010, 2015]
76 4110 Scott Bevan 2011-07-01 00:00:00 2011 England GB4 1218 Torquay United England GB4 ... NaN NaN NaN NaN NaN 0.0 False 32.0 31.294277 (2010, 2015]
77 4110 Scott Bevan 2008-09-25 00:00:00 2008 England GB4 3054 Shrewsbury Town England Other England ... NaN NaN NaN NaN NaN 0.0 False 29.0 28.293531 (2005, 2010]
78 4110 Scott Bevan 2008-01-31 00:00:00 2007 England Other England 1195 Kidderminster England GB4 ... NaN NaN NaN NaN NaN 0.0 False 28.0 27.294195 (2005, 2010]
79 4110 Scott Bevan 2006-07-01 00:00:00 2006 England GB4 991 MK Dons England Other England ... NaN NaN NaN NaN NaN 0.0 False 27.0 26.294859 (2005, 2010]
80 4110 Scott Bevan 2005-10-29 00:00:00 2005 England GB3 991 MK Dons England Other England ... NaN NaN NaN NaN NaN 0.0 True 26.0 25.295523 (2000, 2005]
81 4110 Scott Bevan 2004-03-01 00:00:00 2003 England GB1 180 Southampton England Other England ... NaN NaN NaN NaN NaN 0.0 False 24.0 23.294113 (2000, 2005]
82 4110 Scott Bevan 2002-08-01 00:00:00 2002 England GB1 180 Southampton England Other England ... NaN NaN NaN NaN NaN 0.0 True 23.0 22.294777 (2000, 2005]
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
350600 426344 Ian Molloy 2016-01-23 00:00:00 2015 NaN NaN 75 Unknown Ireland IR1 ... NaN NaN NaN NaN NaN 0.0 False 19.0 18.094827 (2010, 2015]
350601 426344 Ian Molloy 2015-09-01 00:00:00 2015 England GBJG 10161 Leeds United U18 NaN NaN ... NaN NaN NaN NaN NaN 0.0 False 19.0 18.094827 (2010, 2015]
350602 426344 Ian Molloy 2013-07-01 00:00:00 2013 Ireland Other Ireland 6142 Cherry Orchard FC England GBJG ... NaN NaN NaN NaN NaN 0.0 False 17.0 16.096155 (2010, 2015]
350603 343271 Oisin Hassett 2016-01-01 00:00:00 2015 Ireland Other Ireland 32533 Finn Harps U20 Ireland IR1 ... NaN NaN NaN NaN NaN NaN False 18.0 17.881271 (2010, 2015]
350604 365180 Lee Grace 2015-01-27 00:00:00 2014 Ireland Other Ireland 32623 Carrick United Ireland Other Ireland ... NaN NaN NaN NaN NaN 0.0 False 22.0 21.084622 (2010, 2015]
350605 426347 Karl Chambers 2016-01-01 00:00:00 2015 Ireland Other Ireland 32613 Longford U20 Ireland IR1 ... NaN NaN NaN NaN NaN NaN False 19.0 18.568485 (2010, 2015]
350606 426347 Karl Chambers 2015-07-01 00:00:00 2015 Ireland Other Ireland 33053 Sacred Heart Ireland Other Ireland ... NaN NaN NaN NaN NaN 0.0 False 19.0 18.568485 (2010, 2015]
350607 235756 Jordan Allan 2016-01-01 00:00:00 2015 NaN NaN 515 Unattached Ireland IR1 ... NaN NaN NaN NaN NaN NaN False 20.0 19.899108 (2010, 2015]
350608 235756 Jordan Allan 2015-07-01 00:00:00 2015 Scotland Other Scotland 3030 Montrose NaN NaN ... NaN NaN NaN NaN NaN NaN False 20.0 19.899108 (2010, 2015]
350609 235756 Jordan Allan 2015-01-30 00:00:00 2014 Scotland Other Scotland 3026 Morton Scotland Other Scotland ... NaN NaN NaN NaN NaN 0.0 False 19.0 18.899772 (2010, 2015]
350610 235756 Jordan Allan 2014-07-18 00:00:00 2014 Scotland Other Scotland 9044 Dundee United FC U20 Scotland Other Scotland ... NaN NaN NaN NaN NaN 0.0 False 19.0 18.899772 (2010, 2015]
350611 235756 Jordan Allan 2013-12-20 00:00:00 2013 Scotland Other Scotland 9044 Dundee United FC U20 Scotland Other Scotland ... NaN NaN NaN NaN NaN 0.0 True 18.0 17.900436 (2010, 2015]
350612 204398 Craig McCabe 2013-01-01 00:00:00 2012 Ireland Other Ireland 39055 Curracloe Ireland Other Ireland ... NaN NaN NaN http://twitter.com/cmcmccabe8 NaN 0.0 False 19.0 18.634195 (2010, 2015]
350613 204398 Craig McCabe 2012-01-01 00:00:00 2011 Ireland Other Ireland 26765 Wexford Youths Ireland Other Ireland ... NaN NaN NaN http://twitter.com/cmcmccabe8 NaN 0.0 False 18.0 17.634859 (2010, 2015]
350614 426352 Curtis Murphy 2016-01-01 00:00:00 2015 Ireland Other Ireland 15293 Shamrock Rovers Ireland IR1 ... NaN NaN NaN NaN NaN 0.0 False 19.0 18.472659 (2010, 2015]
350615 426352 Curtis Murphy 2015-07-01 00:00:00 2015 Ireland Other Ireland 15436 St. Pats Ireland Other Ireland ... NaN NaN NaN NaN NaN 0.0 False 19.0 18.472659 (2010, 2015]
350625 426345 Cian Fay 2016-01-01 00:00:00 2015 Ireland Other Ireland 32613 Longford U20 Ireland IR1 ... NaN NaN NaN NaN NaN NaN False 17.0 16.452083 (2010, 2015]
350626 223995 Eric Molloy 2012-01-01 00:00:00 2011 Ireland Other Ireland 35618 Arklow Town Ireland Other Ireland ... NaN NaN NaN NaN NaN 0.0 False 19.0 18.053759 (2010, 2015]
350627 186108 Chris Kenny 2015-07-01 00:00:00 2015 Ireland Other Ireland 49650 Shamrock Ireland IR1 ... NaN NaN NaN NaN NaN 0.0 False 25.0 24.663066 (2010, 2015]
350628 186108 Chris Kenny 2011-01-01 00:00:00 2010 Ireland Other Ireland 26765 Wexford Youths Ireland Other Ireland ... NaN NaN NaN NaN NaN NaN False 20.0 19.663648 (2005, 2010]
350629 175743 Craig Roddan 2016-01-27 00:00:00 2015 England Other England 3257 Witton Albion Ireland IR1 ... NaN NaN NaN NaN NaN 0.0 False 22.0 21.695175 (2010, 2015]
350630 175743 Craig Roddan 2015-02-14 00:00:00 2014 NaN NaN 515 Unattached England Other England ... NaN NaN NaN NaN NaN NaN False 21.0 20.695839 (2010, 2015]
350631 175743 Craig Roddan 2015-01-06 00:00:00 2014 England GB4 3688 Accrington St. NaN NaN ... NaN NaN NaN NaN NaN NaN False 21.0 20.695839 (2010, 2015]
350632 175743 Craig Roddan 2014-11-07 00:00:00 2014 NaN NaN 515 Unattached England GB4 ... NaN NaN NaN NaN NaN NaN False 21.0 20.695839 (2010, 2015]
350633 175743 Craig Roddan 2014-07-01 00:00:00 2014 England GB1 31 Liverpool NaN NaN ... NaN NaN NaN NaN NaN NaN False 21.0 20.695839 (2010, 2015]
350634 175743 Craig Roddan 2014-01-04 00:00:00 2013 England GB1 31 Liverpool England GB4 ... NaN NaN NaN NaN NaN 0.0 True 20.0 19.696503 (2010, 2015]
350635 175743 Craig Roddan 2013-11-28 00:00:00 2013 England GB1 31 Liverpool England GB3 ... NaN NaN NaN NaN NaN 0.0 True 20.0 19.696503 (2010, 2015]
350636 175743 Craig Roddan 2013-07-01 00:00:00 2013 England GB21 9252 Liverpool U21 England GB1 ... NaN NaN NaN NaN NaN NaN False 20.0 19.696503 (2010, 2015]
350637 175743 Craig Roddan 2011-07-01 00:00:00 2011 England GBJG 6922 Liverpool U18 England GB21 ... NaN NaN NaN NaN NaN NaN False 18.0 17.695093 (2010, 2015]
350638 175743 Craig Roddan 2009-07-01 00:00:00 2009 England Other England 12808 Wigan U18 England GBJG ... NaN NaN NaN NaN NaN NaN False 16.0 15.696421 (2005, 2010]

200433 rows × 59 columns


In [165]:
t=transfers[~transfers.fromLeague.str.startswith('Other ').fillna(True)]
t=t[t.toCountry!=t.fromCountry]
#t=t[t.toLeague=='GB1']
t.groupby(['season','toLeague','toTeamId']).sum()[['feeValue']].unstack(level=0).reset_index().groupby('toLeague').sum()['feeValue'].sort_values(2015,ascending=False)[:10].T.plot.line()


Out[165]:
<matplotlib.axes._subplots.AxesSubplot at 0x1106bd650>

In [135]:
t[t.fromCountry.str.contains('France')&(t.season==2014)]


Out[135]:
id playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... dayOfDeath facebook instagram twitter website feeValue isLoan age ageFloat period
5821 39152 Falcao 2014-09-01 00:00:00 2014 France FR1 162 Monaco England GB1 ... NaN https://www.facebook.com/Falcao-221940704484621 NaN https://twitter.com/FALCAO NaN 7600000.0 True 28.0 27.891059 (2010, 2015]

1 rows × 59 columns


In [119]:
countries=['Brazil','Serbia','Croatia','Sweden','Norway','Argentina','Nigeria','England','France','Germany']
countries=['Romania','Cyprus','Greece']
countries=['England','France','Germany','Spain','Italy']
countries=['Poland','Hungary','Slovakia','Czech Republic','d']


t=transfers[(transfers.fromCountry.isin(uefa))&(transfers.fromCountry.notnull())&(transfers.fromCountry!=transfers.Nationality)]
t=transfers[(transfers.fromCountry.isin(uefa))&(transfers.fromCountry.notnull())]
s=t[t.season>2000].groupby(['season','fromCountry'])['duration'].mean()
(s).unstack() #.plot.line(figsize=(10,10),colormap='Set1')


Out[119]:
fromCountry Albania Andorra Armenia Austria Azerbaijan Belarus Belgium Bosnia-Herzegovina Bulgaria Croatia ... Scotland Serbia Slovakia Slovenia Spain Sweden Switzerland Turkey Ukraine Wales
season
2001.0 923.666667 365.000000 731.000000 702.984127 913.500000 343.166667 758.594118 780.409091 551.729167 533.402778 ... 721.178947 412.962500 951.282051 630.853659 675.061303 1089.448980 566.451613 609.656250 541.000000 274.000000
2002.0 486.666667 NaN 632.800000 776.007299 834.428571 662.851852 771.231707 319.687500 530.191176 716.215686 ... 706.634921 531.750000 752.305556 451.723214 775.372549 1161.065217 693.477157 631.471698 587.847826 274.000000
2003.0 794.545455 NaN 365.000000 629.718391 1095.333333 576.093750 696.043189 425.818182 583.592593 692.982301 ... 820.643836 628.882812 672.813953 662.901786 786.890909 957.052632 634.966825 616.307692 584.605000 745.600000
2004.0 491.294118 NaN 593.000000 616.349614 744.600000 552.279070 708.835938 510.880952 609.329114 705.453333 ... 806.157303 645.848739 740.787879 841.462810 751.879747 1023.939655 644.571970 528.886752 507.104072 550.000000
2005.0 507.846154 NaN 735.166667 662.027484 334.333333 538.535714 638.789116 623.159420 632.008929 573.676768 ... 718.945274 673.711656 590.074380 728.251969 667.549902 799.636364 614.223443 498.947917 544.926573 762.000000
2006.0 540.571429 NaN 522.666667 648.116981 517.119048 728.444444 632.180873 523.298851 601.023810 463.772201 ... 691.836431 594.045455 595.180556 680.269737 719.812403 710.545455 642.349057 478.505831 596.635015 455.500000
2007.0 650.058824 181.000000 1080.100000 625.412975 519.780000 592.433962 618.319106 500.737589 666.456853 542.387179 ... 616.833333 454.869688 658.184713 553.081967 639.454777 736.735178 522.102493 486.293578 618.758537 805.500000
2008.0 586.176471 NaN 647.375000 559.225115 567.176471 589.136364 635.217391 461.000000 543.031128 447.706546 ... 617.134969 497.432500 563.363636 557.969565 595.603604 820.675768 573.698701 483.868833 547.272527 420.666667
2009.0 353.428571 365.000000 464.333333 557.396923 487.080808 441.666667 594.850258 437.635783 519.579747 503.208661 ... 607.947917 452.193900 553.140221 564.386986 609.057416 807.975779 594.508642 465.384961 508.139918 346.600000
2010.0 368.269841 NaN 456.647059 552.191424 531.807143 504.098765 636.006957 430.821530 512.019608 497.159664 ... 593.306413 452.944643 553.373077 524.468468 641.026869 807.069444 581.017588 453.454259 555.892393 312.250000
2011.0 382.630769 761.000000 591.700000 606.530159 454.406504 487.573529 620.396321 391.380631 488.991803 491.873278 ... 548.823864 456.862355 588.579336 467.469512 621.984598 801.600503 590.277273 483.526580 538.562130 429.500000
2012.0 323.527778 NaN 609.950000 563.420144 576.186813 406.555556 622.719101 418.798077 448.621514 458.304749 ... 590.681416 422.324047 591.400000 553.331361 595.815937 779.073418 563.141573 470.873430 571.306122 333.600000
2013.0 352.464286 NaN 335.777778 564.036657 530.869822 404.051546 598.586314 430.625255 428.296813 466.829023 ... 547.449791 438.743083 580.075812 515.054487 612.951467 777.867168 581.772727 455.524829 640.185550 631.800000
2014.0 342.298507 730.000000 356.692308 575.306003 521.871508 536.235294 614.354985 435.441065 451.597015 445.003115 ... 502.445148 416.246398 597.524194 585.856589 585.249089 708.789474 584.070136 428.950211 584.550285 447.700000
2015.0 319.647059 204.666667 229.655172 560.576677 582.190722 524.137500 612.672619 442.433812 485.705446 468.500960 ... 523.523422 441.856712 652.952899 568.046358 584.807829 773.253165 575.156177 437.353765 566.093541 382.714286

15 rows × 60 columns


In [8]:
#transfers.merge(countryInfo,right_index=True,left_on='fromCountry',how='left')
s=transfers[(transfers.age>20)&(transfers.season>1994)&(transfers.fromLeague.isin(leagueList))&(transfers.duration>0)&(transfers.fromCountry.notnull())]
s=s.merge(countryInfo[['marketTier']],right_index=True,left_on='fromCountry',how='left')
#s=s[s.marketTier==2]
ss=s.groupby(['season','marketTier'])['duration']
(ss.describe()/366).unstack(level=0).swaplevel().ix['mean'].T.plot.line(figsize=(10,10))


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x10934e150>

In [182]:
tier1=['England','France','Spain','Germany','France']
t=transfers[(transfers.season>2000)&(transfers.feeValue>0)]
allTransfers=t[(t.fromCountry!=t.toCountry)&(t.toCountry.isin(tier1))].groupby('season')['id'].count()
internalTransfers=t[(t.fromCountry!=t.toCountry)&(t.toCountry.isin(tier1))&(t.fromCountry.isin(tier1))].groupby('season')['id'].count()

s=DataFrame({'all':allTransfers,'internal':internalTransfers})
s['internalPct']=s.internal/s['all']
s.internalPct.plot.line()


Out[182]:
<matplotlib.axes._subplots.AxesSubplot at 0x11b1b0950>

In [182]:
tier1=['England','France','Spain','Germany','France']
t=transfers[(transfers.season>2000)&(transfers.feeValue>0)]
allTransfers=t[(t.fromCountry!=t.toCountry)&(t.toCountry.isin(tier1))].groupby('season')['id'].count()
internalTransfers=t[(t.fromCountry!=t.toCountry)&(t.toCountry.isin(tier1))&(t.fromCountry.isin(tier1))].groupby('season')['id'].count()

s=DataFrame({'all':allTransfers,'internal':internalTransfers})
s['internalPct']=s.internal/s['all']
s.internalPct.plot.line()


Out[182]:
<matplotlib.axes._subplots.AxesSubplot at 0x11b1b0950>

In [113]:
s


Out[113]:
id playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... website feeValue isLoan age ageFloat period mvDelta duration durationWithLoans fromTeamClass
15547 50089 Jonas Portin 2015-01-01 2014.0 Italy IT1 130.0 Parma NaN NaN ... NaN NaN False 28.0 27.25586 (2010, 2015] 0.0 184.0 184.0 the rest
17151 107919 Mika Lehkosuo 1999-07-01 1999.0 Italy IT1 839.0 Perugia Finland FI1 ... NaN NaN False 29.0 28.98075 (1995, 2000] 0.0 181.0 181.0 the rest
17280 287354 Francesco Tahiraj 2015-08-18 2015.0 Italy IT1 416.0 Torino Slovenia SL1 ... NaN NaN False 19.0 18.27827 (2010, 2015] 0.0 398.0 208.0 the rest
17509 199252 Alessio Innocenti 2015-07-01 2015.0 Italy IT1 5.0 AC Milan Italy IT3C ... NaN NaN False 22.0 21.90599 (2010, 2015] -25000.0 1461.0 307.0 top 20
17627 85881 Fabio Lebran 2009-08-01 2009.0 Italy IT1 130.0 Parma Italy IT3B ... NaN NaN False 22.0 21.97170 (2005, 2010] 0.0 31.0 31.0 the rest
17629 85881 Fabio Lebran 2010-08-01 2010.0 Italy IT1 130.0 Parma Italy IT2 ... NaN 150000.0 False 23.0 22.97104 (2005, 2010] 0.0 31.0 31.0 the rest
17634 85881 Fabio Lebran 2014-07-01 2014.0 Italy IT1 130.0 Parma Italy IT2 ... NaN NaN False 27.0 26.97112 (2010, 2015] 0.0 731.0 181.0 the rest
17672 133396 Francesco Checcucci 2011-07-01 2011.0 Italy IT1 862.0 Chievo Verona Italy IT2 ... NaN NaN False 22.0 21.79100 (2010, 2015] 100000.0 30.0 30.0 the rest
17675 133396 Francesco Checcucci 2014-08-29 2014.0 Italy IT1 130.0 Parma Italy IT3C ... NaN NaN False 25.0 24.79175 (2010, 2015] -50000.0 396.0 387.0 the rest
17773 189521 Jorman Aguilar 2014-08-11 2014.0 Italy IT1 130.0 Parma Portugal PO2 ... NaN NaN False 20.0 19.30772 (2010, 2015] -25000.0 406.0 182.0 the rest
18021 88695 Jean Mbida 2014-01-04 2013.0 Italy IT1 1627.0 Catania Italy Other Italy ... NaN 90000.0 False 23.0 22.73284 (2010, 2015] 100000.0 520.0 516.0 the rest
19833 38274 Gorazd Zajc 2007-01-01 2006.0 Italy IT1 1387.0 AC Siena Slovenia SL1 ... NaN NaN False 19.0 18.01269 (2005, 2010] 0.0 153.0 153.0 the rest
22879 198851 Sebastián Sosa 2014-08-31 2014.0 Italy IT1 458.0 US Palermo Italy IT1 ... NaN NaN False 20.0 19.80602 (2010, 2015] -750000.0 732.0 194.0 the rest
22881 198851 Sebastián Sosa 2015-01-14 2014.0 Italy IT1 749.0 FC Empoli Switzerland Other Switzerland ... NaN NaN False 20.0 19.80602 (2010, 2015] -200000.0 136.0 135.0 the rest
25898 164833 Krisztián Tamás 2015-08-06 2015.0 Italy IT1 5.0 AC Milan Italy IT2 ... NaN NaN False 20.0 19.70745 (2010, 2015] 150000.0 401.0 184.0 top 20
26587 137104 Milan Bortel 2009-07-01 2009.0 Italy IT1 1627.0 Catania Italy IT3B ... NaN NaN False 22.0 21.73898 (2005, 2010] 0.0 30.0 30.0 the rest
27604 167817 Marco Migliorini 2013-01-03 2012.0 Italy IT1 416.0 Torino Italy IT3A ... NaN NaN False 20.0 19.99493 (2010, 2015] 0.0 180.0 180.0 the rest
30519 43243 Zdenek Zlámal 2011-07-01 2011.0 Italy IT1 410.0 Udinese Calcio Italy IT2 ... NaN 500000.0 False 26.0 25.15589 (2010, 2015] 0.0 730.0 303.0 the rest
30522 43243 Zdenek Zlámal 2012-07-01 2012.0 Italy IT1 410.0 Udinese Calcio Czech Republic TS1 ... NaN NaN False 27.0 26.15523 (2010, 2015] 0.0 1.0 1.0 the rest
35157 344896 Mateus 2015-08-01 2015.0 Italy IT1 749.0 FC Empoli Italy Other Italy ... NaN NaN False 25.0 24.68497 (2010, 2015] 0.0 338.0 178.0 the rest
35435 241116 Luke Montebello 2013-07-01 2013.0 Italy IT1 1210.0 AS Livorno Malta MAL1 ... NaN NaN False 18.0 17.38845 (2010, 2015] 0.0 365.0 365.0 the rest
35510 280418 Gianluca Nucera 2014-08-08 2014.0 Italy IT1 130.0 Parma Italy IT3B ... NaN 0.0 False 20.0 19.45009 (2010, 2015] 0.0 382.0 189.0 the rest
35591 140037 Simone Bezziccheri 2013-07-11 2013.0 Italy IT1 130.0 Parma Malta MAL1 ... NaN NaN False 20.0 19.74031 (2010, 2015] 0.0 162.0 161.0 the rest
36053 167293 Alain Faccini 2012-08-30 2012.0 Italy IT1 1387.0 AC Siena Malta MAL1 ... NaN NaN False 21.0 20.20575 (2010, 2015] -25000.0 791.0 242.0 the rest
36297 61399 Carlo Polli 2011-07-01 2011.0 Italy IT1 252.0 Genoa Malta MAL1 ... NaN 0.0 False 22.0 21.89778 (2010, 2015] 0.0 546.0 365.0 the rest
36469 76112 Vincent Kouadio 2012-02-01 2011.0 Italy IT1 1627.0 Catania Malta MAL1 ... NaN NaN False 21.0 20.00315 (2010, 2015] 0.0 31.0 31.0 the rest
38156 33624 Angelo Paradiso 1999-07-01 1999.0 Italy IT1 1005.0 Lecce Italy IT2 ... NaN NaN False 22.0 21.87861 (1995, 2000] 0.0 365.0 365.0 the rest
38336 86484 Mattia Bottani 2012-07-01 2012.0 Italy IT1 252.0 Genoa Switzerland Other Switzerland ... NaN 0.0 False 21.0 20.60823 (2010, 2015] 100000.0 366.0 335.0 the rest
38372 39687 Orlando Urbano 2007-07-01 2007.0 Italy IT1 506.0 Juventus Italy IT3B ... NaN NaN False 23.0 22.56309 (2005, 2010] 0.0 1461.0 546.0 top 20
40208 23360 Iacopo La Rocca 2005-07-01 2005.0 Italy IT1 2251.0 Treviso Italy Other Italy ... NaN NaN False 21.0 20.87380 (2000, 2005] 0.0 365.0 181.0 the rest
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
348852 3177 Gianfranco Zola 2005-07-01 2005.0 Italy IT1 1390.0 Cagliari Calcio Australia Other Australia ... NaN 0.0 False 39.0 38.49497 (2000, 2005] 0.0 731.0 731.0 the rest
348907 15458 Daniele Daino 2001-07-01 2001.0 Italy IT1 5.0 Milan England GB1 ... NaN NaN False 22.0 21.31734 (2000, 2005] 0.0 1461.0 700.0 top 20
348909 15458 Daniele Daino 2002-07-01 2002.0 Italy IT1 839.0 Perugia Italy IT2 ... NaN NaN False 23.0 22.31668 (2000, 2005] 0.0 181.0 181.0 the rest
348911 15458 Daniele Daino 2008-07-01 2008.0 Italy IT1 1025.0 Bologna NaN NaN ... NaN NaN False 29.0 28.31543 (2005, 2010] 0.0 1461.0 1461.0 the rest
348929 3164 Mario Stanic 2000-07-01 2000.0 Italy IT1 130.0 AC Parma England GB1 ... NaN 8400000.0 False 28.0 27.72678 (1995, 2000] 0.0 1461.0 1461.0 the rest
348962 3159 Valerio Di Cesare 2013-08-08 2013.0 Italy IT1 416.0 Torino Italy IT2 ... NaN NaN False 30.0 29.61320 (2010, 2015] -300000.0 1134.0 1134.0 the rest
348991 3155 Winston Bogarde 1997-07-01 1997.0 Italy IT1 5.0 Milan Spain ES1 ... NaN 3700000.0 False 27.0 26.19629 (1995, 2000] 0.0 181.0 181.0 top 20
348997 3154 Marcel Desailly 1998-07-01 1998.0 Italy IT1 5.0 Milan England GB1 ... https://www.marcel-desailly.com 6330000.0 False 30.0 29.31751 (1995, 2000] 0.0 1642.0 1642.0 top 20
349011 3151 Carlo Cudicini 1995-07-01 1995.0 Italy IT1 5.0 Milan Italy Other Italy ... NaN 0.0 False 22.0 21.32008 NaN 0.0 1095.0 1095.0 top 20
349013 3151 Carlo Cudicini 1997-07-01 1997.0 Italy IT1 398.0 Lazio Italy IT2 ... NaN 0.0 False 24.0 23.32149 (1995, 2000] 0.0 365.0 365.0 top 20
349038 3144 Robbie Keane 2001-07-01 2001.0 Italy IT1 46.0 Inter England GB1 ... NaN 18000000.0 False 21.0 20.48502 (2000, 2005] 0.0 365.0 181.0 top 20
349049 3143 Juan Sebastián Verón 1998-07-01 1998.0 Italy IT1 1038.0 Sampdoria Italy IT1 ... NaN 17500000.0 False 23.0 22.81772 (1995, 2000] 0.0 730.0 730.0 the rest
349050 3143 Juan Sebastián Verón 1999-07-01 1999.0 Italy IT1 130.0 AC Parma Italy IT1 ... NaN 30000000.0 False 24.0 23.81705 (1995, 2000] 0.0 365.0 365.0 the rest
349051 3143 Juan Sebastián Verón 2001-07-01 2001.0 Italy IT1 398.0 Lazio England GB1 ... NaN 42600000.0 False 26.0 25.81846 (2000, 2005] 0.0 731.0 731.0 top 20
349104 3133 Nwankwo Kanu 1999-01-01 1998.0 Italy IT1 46.0 Inter England GB1 ... NaN 6250000.0 False 22.0 21.41865 (1995, 2000] 0.0 914.0 914.0 top 20
349223 3113 Laurent Blanc 2001-08-30 2001.0 Italy IT1 46.0 Inter England GB1 ... NaN 0.0 False 36.0 35.11913 (2000, 2005] 0.0 791.0 791.0 top 20
349303 3098 Olof Mellberg 2009-07-01 2009.0 Italy IT1 506.0 Juventus Greece GR1 ... NaN 2500000.0 False 32.0 31.32987 (2005, 2010] 1500000.0 365.0 365.0 top 20
349310 3095 Jesper Blomqvist 1997-07-01 1997.0 Italy IT1 5.0 Milan Italy IT1 ... NaN 2500000.0 False 23.0 22.90533 (1995, 2000] 0.0 365.0 365.0 top 20
349311 3095 Jesper Blomqvist 1998-07-01 1998.0 Italy IT1 130.0 AC Parma England GB1 ... NaN 6500000.0 False 24.0 23.90467 (1995, 2000] 0.0 365.0 365.0 the rest
349354 3087 Mark Fish 1997-07-01 1997.0 Italy IT1 398.0 Lazio England GB1 ... NaN 3000000.0 False 23.0 22.80403 (1995, 2000] 0.0 365.0 365.0 top 20
349673 916 Christian Ziege 1999-07-01 1999.0 Italy IT1 5.0 Milan England GB1 ... NaN 6000000.0 False 27.0 26.91636 (1995, 2000] 0.0 730.0 730.0 top 20
349806 171813 Djibril Diawara 2002-01-01 2001.0 Italy IT1 416.0 Torino Italy IT2 ... NaN NaN False 26.0 25.99643 (2000, 2005] 0.0 915.0 184.0 the rest
349835 55962 Sixto Peralta 2002-07-01 2002.0 Italy IT1 46.0 Inter Argentina AR1N ... NaN 2000000.0 False 23.0 22.71368 (2000, 2005] 0.0 730.0 365.0 top 20
349864 103679 Roberto Di Matteo 1996-07-01 1996.0 Italy IT1 398.0 Lazio England GB1 ... NaN 5500000.0 False 26.0 25.59395 (1995, 2000] 0.0 1096.0 1096.0 top 20
350170 4291 Samuele Dalla Bona 2006-08-09 2006.0 Italy IT1 5.0 AC Milan Italy IT2 ... NaN 0.0 False 25.0 24.58367 (2005, 2010] 1500000.0 1500.0 404.0 top 20
350174 4291 Samuele Dalla Bona 2011-08-01 2011.0 Italy IT1 6195.0 SSC Napoli Italy Other Italy ... NaN 0.0 False 30.0 29.58309 (2010, 2015] -150000.0 1818.0 365.0 the rest
350330 4226 Fabrizio Ravanelli 1996-07-01 1996.0 Italy IT1 506.0 Juventus England GB1 ... NaN 9780000.0 False 28.0 27.05600 (1995, 2000] 0.0 1461.0 1461.0 top 20
350333 4226 Fabrizio Ravanelli 2001-07-01 2001.0 Italy IT1 398.0 Lazio England GB1 ... NaN 0.0 False 33.0 32.05815 (2000, 2005] 0.0 547.0 547.0 top 20
350460 4123 Stefan Schwarz 1998-07-01 1998.0 Italy IT1 430.0 Fiorentina Spain ES1 ... NaN 3500000.0 False 29.0 28.70695 (1995, 2000] 0.0 1096.0 1096.0 top 20
350598 4 Youri Djorkaeff 1999-07-01 1999.0 Italy IT1 46.0 Inter Germany L1 ... NaN 1500000.0 False 31.0 30.81514 (1995, 2000] 0.0 1095.0 1095.0 top 20

3920 rows × 63 columns


In [6]:
#transfers.merge(countryInfo,right_index=True,left_on='fromCountry',how='left')
transfers['fromTeamClass']=pd.Series(np.where(transfers.fromTeamId.isin(top20clubids),'top 20','the rest'))
s=transfers[(transfers.age>23)&(transfers.season>1994)&(transfers.Nationality.isin(['France','Spain','Germany','Italy','England','Brazil','Norway']))&(transfers.duration>0)&(transfers.fromCountry.notnull())]
s=s.merge(countryInfo[['marketTier']],right_index=True,left_on='fromCountry',how='left')
#s=s[s.marketTier==2]
ss=s.groupby(['season','Nationality'])['duration']
(ss.describe()/366).unstack(level=0).swaplevel().ix['mean'].T.plot.line(figsize=(10,10))


/Users/sunkevin/anaconda/lib/python2.7/site-packages/pandas/tools/merge.py:714: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  rlab = rizer.factorize(rk)
Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x10e0c64d0>

In [190]:
transfers.groupby('positionGroup').count()['id']


Out[190]:
positionGroup
Defence       103896
Goalkeeper     33911
Midfield      123292
Striker        89527
Name: id, dtype: int64

In [193]:
#transfers.merge(countryInfo,right_index=True,left_on='fromCountry',how='left')
transfers['intlStatus']=pd.Series(np.where(transfers.intlCaps>0,'international','not international'))
s=transfers[(transfers.age>21)&(transfers.season>1994)&(transfers.duration>0)&(transfers.fromCountry.notnull())&(transfers.positionGroup=='Midfield')]
s=s.merge(countryInfo[['marketTier']],right_index=True,left_on='fromCountry',how='left')
#s=s[s.marketTier==2]
ss=s.groupby(['season','mainPosition'])['duration']
(ss.describe()/366).unstack(level=0).swaplevel().ix['mean'].T.plot.line(figsize=(10,10))


Out[193]:
<matplotlib.axes._subplots.AxesSubplot at 0x132641c90>

In [3]:
transfers[transfers.age>20].groupby('age')['duration'].mean().plot.bar()


Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x1071c0f90>

In [131]:
t=transfers[(transfers.feeValue>0)&(transfers.season>2000)].groupby('season')['duration'].mean()
(t/366).plot.line()


Out[131]:
<matplotlib.axes._subplots.AxesSubplot at 0x11c20a8d0>

In [7]:
top20clubids=transfers.groupby('toTeamId')[['feeValue']].sum().merge(DataFrame({'teamName':teamIdMap}), left_index=True,right_index=True,how='left').sort_values('feeValue',ascending=False).iloc[:20].index

In [41]:
def getTierOnePct(t):
    return t[t.marketTier==1]['feeValue'].sum() / t.feeValue.sum()

s=transfers[(transfers.season>1994)&(transfers.fromLeague.isin(leagueList))&(transfers.duration>0)]
s=s.merge(countryInfo[['marketTier']].fillna(4),right_index=True,left_on='fromCountry',how='left')
ss=s.groupby(['season','marketTier'])
(ss.sum()).reset_index().groupby('season').apply(getTierOnePct).plot.line()


Out[41]:
<matplotlib.axes._subplots.AxesSubplot at 0x10e29c2d0>

In [7]:
transfers[transfers.id==7767][['fromTeamName','toTeamName','date','duration','isLoan']]


Out[7]:
fromTeamName toTeamName date duration isLoan
335477 Atl. Madrid B Atlético Madrid 2001-07-01 NaN False
335478 Atlético Madrid Liverpool 2007-07-04 2194.0 False
335479 Liverpool Chelsea 2011-01-31 1307.0 False
335480 Chelsea AC Milan 2014-08-31 NaN True
335481 Chelsea AC Milan 2015-01-05 1435.0 False
335482 AC Milan Atlético Madrid 2015-01-06 NaN True

In [2]:
#transfers.merge(countryInfo,right_index=True,left_on='fromCountry',how='left')
s=transfers[(transfers.season>1994)&(transfers.fromCountry.isin(uefa))&(transfers.duration>0)]
s=s.merge(countryInfo[['marketTier']].fillna(4),right_index=True,left_on='fromCountry',how='left')
s=s.groupby(['season','marketTier'])['duration']
(s.describe()/366).unstack(level=0).swaplevel().ix['mean'].T.plot.line()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-d9059e0df7a7> in <module>()
      1 #transfers.merge(countryInfo,right_index=True,left_on='fromCountry',how='left')
----> 2 s=transfers[(transfers.season>1994)&(transfers.fromCountry.isin(uefa))&(transfers.duration>0)]
      3 s=s.merge(countryInfo[['marketTier']].fillna(4),right_index=True,left_on='fromCountry',how='left')
      4 s=s.groupby(['season','marketTier'])['duration']
      5 (s.describe()/366).unstack(level=0).swaplevel().ix['mean'].T.plot.line()

NameError: name 'uefa' is not defined

In [209]:
def topTransferClubs(t):
    t=t[(t.feeValue>0)&(t.fromCountry!=t.toCountry)].groupby('toTeamId').agg({'feeValue':'sum'}).sort_values('feeValue',ascending=False)
    t['cumPct']=t.feeValue.cumsum()/t.feeValue.sum()
    return t[t.feeValue>t.feeValue.mean()].join(DataFrame({'toTeamName':teamIdMap}),how='left').reset_index().count()

transfers[transfers.season>1994].groupby('season').apply(topTransferClubs).feeValue.plot.line()


Out[209]:
<matplotlib.axes._subplots.AxesSubplot at 0x12ed8e150>

In [225]:
def topTransferCountries(t):
    t=t[(t.feeValue>0)&(t.Nationality!=t.toCountry)].groupby('Nationality').agg({'feeValue':'sum'}).sort_values('feeValue',ascending=False)
    t['cumPct']=t.feeValue.cumsum()/t.feeValue.sum()
    return t[t.cumPct.shift(1)<0.66].reset_index().count()

transfers[transfers.season>1994].groupby('season').apply(topTransferCountries)['cumPct'].plot.line()


Out[225]:
<matplotlib.axes._subplots.AxesSubplot at 0x130b90d10>

In [171]:
def topTransferClubs(t):
    t=t[(t.feeValue>0)&(t.fromCountry!=t.toCountry)].groupby('fromTeamId').agg({'feeValue':'sum'}).sort_values('feeValue',ascending=False)
    t['cumPct']=t.feeValue.cumsum()/t.feeValue.sum()
    return t[t.cumPct.shift(1).fillna(0)<0.666].join(DataFrame({'fromTeamName':teamIdMap}),how='left').reset_index().drop('fromTeamId',axis=1).count()

transfers[transfers.season>2000].groupby('season').apply(topTransferClubs).feeValue.plot.line()


Out[171]:
<matplotlib.axes._subplots.AxesSubplot at 0x12482eb90>

In [48]:
t=nonloans[nonloans.feeValue>0]
s=t[t.fromCountry!=t.toCountry].groupby(['fromCountry','toCountry']).sum()[['feeValue']].sort_values('feeValue',ascending=False).reset_index()
s['cumpct']=s['feeValue'].cumsum()/s['feeValue'].sum()
s=s[s.cumpct<0.66]
s.drop('cumpct',axis=1).rename(columns={'fromCountry':'source','toCountry':'target','feeValue':'value'}).to_csv('../html/transfers.csv',index=False)
s


Out[48]:
fromCountry toCountry feeValue cumpct
0 Spain England 1.387615e+09 0.050419
1 France England 1.242044e+09 0.095548
2 England Spain 1.023465e+09 0.132735
3 Italy England 9.050500e+08 0.165620
4 Spain Italy 8.828750e+08 0.197699
5 Italy Spain 7.687000e+08 0.225629
6 Netherlands England 6.246490e+08 0.248326
7 Germany England 5.794300e+08 0.269379
8 Portugal Spain 5.652500e+08 0.289917
9 Portugal England 5.097500e+08 0.308439
10 France Spain 4.798300e+08 0.325873
11 Brazil Spain 3.875000e+08 0.339953
12 Italy France 3.695000e+08 0.353379
13 Argentina Spain 3.458700e+08 0.365946
14 Scotland England 3.446290e+08 0.378468
15 France Italy 3.420350e+08 0.390895
16 Italy Germany 3.416000e+08 0.403307
17 England Italy 2.917750e+08 0.413909
18 Argentina Italy 2.820500e+08 0.424157
19 England France 2.719900e+08 0.434040
20 Brazil Italy 2.558180e+08 0.443335
21 Germany Italy 2.508700e+08 0.452450
22 Russia England 2.486600e+08 0.461485
23 Spain France 2.444000e+08 0.470365
24 Brazil Ukraine 2.369850e+08 0.478976
25 Brazil Germany 2.166300e+08 0.486847
26 Netherlands Spain 2.144100e+08 0.494638
27 Spain Germany 2.130300e+08 0.502378
28 Portugal Russia 2.128000e+08 0.510110
29 Brazil France 2.013600e+08 0.517427
30 Portugal France 2.013500e+08 0.524742
31 Germany Spain 1.967500e+08 0.531891
32 England Germany 1.936580e+08 0.538928
33 Brazil England 1.901400e+08 0.545837
34 Portugal Italy 1.812200e+08 0.552421
35 Belgium England 1.790900e+08 0.558928
36 Spain Portugal 1.751400e+08 0.565292
37 Netherlands Italy 1.678890e+08 0.571392
38 England Scotland 1.600590e+08 0.577208
39 Brazil Portugal 1.536160e+08 0.582789
40 Switzerland Germany 1.527900e+08 0.588341
41 Netherlands Germany 1.520750e+08 0.593867
42 France Germany 1.355600e+08 0.598792
43 Uruguay Italy 1.284100e+08 0.603458
44 Brazil Russia 1.268930e+08 0.608068
45 Argentina Portugal 1.221700e+08 0.612507
46 Italy Russia 1.086000e+08 0.616453
47 Argentina England 1.076150e+08 0.620364
48 Ukraine Russia 1.037750e+08 0.624134
49 Croatia England 1.034500e+08 0.627893
50 England Russia 1.029750e+08 0.631635
51 Ukraine England 1.027800e+08 0.635369
52 England Turkey 1.005650e+08 0.639023
53 France Turkey 9.964000e+07 0.642643
54 Norway England 9.783000e+07 0.646198
55 Czech Republic Germany 8.690000e+07 0.649356
56 Belgium Germany 8.600000e+07 0.652480
57 Spain Russia 8.270000e+07 0.655485
58 Italy Turkey 8.140000e+07 0.658443

In [3]:
big5leagues=['GB1','FR1','L1','IT1','ES1']
#big5leagues=['ZYP1']
big5ids=nonloans[(nonloans.fromLeague.isin(big5leagues))|(nonloans.toLeague.isin(big5leagues))].id
t=nonloans[(nonloans.feeValue>0)&(nonloans.id.isin(big5ids))]
t=nonloans[nonloans.season.between(1995,2015)]
#t=t[t.feeValue>0]
s=t[t.fromCountry!=t.toCountry].groupby(['fromCountry','toCountry']).count()[['id']].sort_values('id',ascending=False).reset_index()
#s.groupby('toCountry').apply(lambda x:x[:5]).reset_index(drop=True).sort_values('id',ascending=False).reset_index(drop=True)
#s['cumpct']=s['id'].cumsum()/s['id'].sum()
s=s[:100]
#s['value']=pd.qcut(s.id, 10, labels=False)
s['value']=s.id/s.id.max()
s['decile']=pd.qcut(s.id, 10,labels=False)
#s.id=10+s.id.max()-s.id
s=s.rename(columns={'fromCountry':'source','toCountry':'target'})
s.to_csv('../html/transfers.csv',index=False)
s
#DataFrame(pd.concat([s.groupby('source').sum()['id'].fillna(0),s.groupby('target').sum()['id'].fillna(0)],axis=1).sum(axis=1)).


Out[3]:
source target id value decile
0 England Scotland 612 1.000000 9
1 Brazil Portugal 597 0.975490 9
2 Scotland England 568 0.928105 9
3 France Belgium 463 0.756536 9
4 Slovenia Austria 413 0.674837 9
5 Bosnia-Herzegovina Croatia 399 0.651961 9
6 Slovakia Czech Republic 397 0.648693 9
7 France England 380 0.620915 9
8 Czech Republic Slovakia 377 0.616013 9
9 Croatia Bosnia-Herzegovina 370 0.604575 9
10 Belgium Netherlands 359 0.586601 8
11 Serbia Bosnia-Herzegovina 347 0.566993 8
12 Greece Cyprus 345 0.563725 8
13 Germany Turkey 314 0.513072 8
14 Netherlands Belgium 297 0.485294 8
15 Cyprus Greece 278 0.454248 8
16 France Luxembourg 274 0.447712 8
17 Ukraine Russia 271 0.442810 8
18 Spain England 268 0.437908 8
19 Portugal Brazil 260 0.424837 8
20 England Ireland 249 0.406863 7
21 Austria Germany 246 0.401961 7
22 Portugal Spain 241 0.393791 7
23 Portugal Cyprus 235 0.383987 7
24 Bosnia-Herzegovina Serbia 233 0.380719 7
25 Austria Slovenia 229 0.374183 7
26 Belgium France 227 0.370915 7
27 Germany Austria 225 0.367647 7
28 Croatia Slovenia 213 0.348039 7
29 Sweden Norway 210 0.343137 7
... ... ... ... ... ...
70 England United States 138 0.225490 2
71 Switzerland France 137 0.223856 2
72 Portugal Romania 133 0.217320 2
73 Sweden Denmark 127 0.207516 2
74 Turkey Germany 126 0.205882 2
75 England Italy 125 0.204248 2
76 Brazil Spain 124 0.202614 2
77 Denmark Norway 124 0.202614 2
78 Croatia Germany 123 0.200980 2
79 Switzerland Italy 121 0.197712 2
80 Denmark Sweden 120 0.196078 1
81 Spain Argentina 118 0.192810 1
82 Germany Poland 117 0.191176 1
83 Spain France 117 0.191176 1
84 Portugal England 117 0.191176 1
85 Germany Greece 116 0.189542 1
86 Serbia Greece 114 0.186275 1
87 Portugal France 113 0.184641 1
88 Brazil Greece 113 0.184641 1
89 Ireland Northern Ireland 112 0.183007 1
90 Italy France 111 0.181373 0
91 Cyprus Portugal 111 0.181373 0
92 Finland Sweden 111 0.181373 0
93 Luxembourg France 110 0.179739 0
94 Luxembourg Germany 109 0.178105 0
95 Austria Croatia 106 0.173203 0
96 Romania Hungary 106 0.173203 0
97 Norway Denmark 106 0.173203 0
98 Slovakia Poland 105 0.171569 0
99 Belgium Germany 104 0.169935 0

100 rows × 5 columns


In [54]:
big5leagues=['GB1','FR1','L1','IT1','ES1']
#big5leagues=['ZYP1']
big5ids=nonloans[(nonloans.toTeamId==148)].id
t=nonloans[(nonloans.feeValue>0)&(nonloans.id.isin(big5ids))]
t=t[t.season.between(1995,2015)]
t=t[t.fromCountry.notnull()&t.toCountry.notnull()&(t.fromLeague.isin(leagueList))]
#t=t[t.feeValue>0]
s=t.groupby(['fromTeamId','toTeamId']).count()[['id']].sort_values('id',ascending=False).reset_index()
#s.groupby('toCountry').apply(lambda x:x[:5]).reset_index(drop=True).sort_values('id',ascending=False).reset_index(drop=True)
#s['cumpct']=s['id'].cumsum()/s['id'].sum()
#s['value']=pd.qcut(s.id, 10, labels=False)
s['value']=s.id/s.id.max()
s['decile']=pd.qcut(s.id, 1,labels=False)*5
#s.id=10+s.id.max()-s.id
s=s.merge(DataFrame({"source":teamIdMap}).reset_index().rename(columns={'index':'fromTeamId'}),how='left')
s=s.merge(DataFrame({"target":teamIdMap}).reset_index().rename(columns={'index':'toTeamId'}),how='left')
s
s.to_csv('../html/transfers.csv',index=False)

In [22]:
def getImportExportRank(sortby='total',cutoff=50):
    def f(t):
        s=t[t.fromCountry!=t.toCountry].groupby(['fromCountry','toCountry']).count()[['id']].sort_values('id',ascending=False)
        s1=s.swaplevel().reset_index().rename(columns={'id':'import','fromCountry':'toCountry','toCountry':'fromCountry'})
        s2=s.reset_index().rename(columns={'id':'export'})
        s3=s2.merge(s1)
        s3['net']=s3['export']-s3['import']
        s3['total']=s3['export']+s3['import']
        s3['netted']=(s3['total']-s3['net'])/2
        s3=s3[s3.net>0]
        return s3.sort_values(sortby,ascending=False)[:cutoff].reset_index(drop=True)
    return f

In [17]:
o=nonloans.groupby('period').apply(getImportExportRank()).unstack(level=0).swaplevel(axis=1).sort_index(level=0,axis=1)
ew = pd.ExcelWriter('../data/output/total_nonloans.xls', encoding='utf-8')
o.to_excel(ew)
ew.save()
o


Out[17]:
period (1995, 2000] (2000, 2005] ... (2005, 2010] (2010, 2015]
fromCountry toCountry export import net total fromCountry toCountry export import ... export import net total fromCountry toCountry export import net total
0 Scotland England 50 44 6 94 England Scotland 145 128 ... 214 201 13 415 England Scotland 205 187 18 392
1 France England 61 20 41 81 Brazil Portugal 177 59 ... 172 158 14 330 Croatia Bosnia-Herzegovina 193 166 27 359
2 Portugal Spain 48 31 17 79 France Belgium 116 61 ... 215 97 118 312 Serbia Bosnia-Herzegovina 194 141 53 335
3 Belgium Netherlands 54 24 30 78 Ukraine Russia 87 83 ... 166 129 37 295 Slovenia Austria 206 114 92 320
4 Argentina Spain 59 12 47 71 Belgium Netherlands 88 70 ... 139 96 43 235 Slovakia Czech Republic 145 125 20 270
5 Ukraine Russia 42 29 13 71 France England 111 42 ... 155 66 89 221 Greece Cyprus 124 115 9 239
6 Brazil Portugal 59 10 49 69 Greece Cyprus 75 58 ... 106 102 4 208 Brazil Portugal 145 92 53 237
7 France Italy 53 16 37 69 Slovakia Czech Republic 69 59 ... 129 71 58 200 France Belgium 154 72 82 226
8 Italy Spain 37 31 6 68 Germany Austria 61 54 ... 116 79 37 195 Belgium Netherlands 109 100 9 209
9 France Belgium 37 26 11 63 Argentina Spain 62 48 ... 97 76 21 173 Serbia Montenegro 97 82 15 179
10 Switzerland Germany 33 19 14 52 France Switzerland 55 54 ... 124 44 80 168 Spain England 110 68 42 178
11 Italy England 35 12 23 47 Slovenia Austria 81 27 ... 105 48 57 153 Croatia Slovenia 108 63 45 171
12 Slovakia Czech Republic 25 20 5 45 Germany Turkey 64 33 ... 106 40 66 146 Portugal Cyprus 101 66 35 167
13 France Switzerland 26 19 7 45 Spain England 61 35 ... 102 38 64 140 Croatia Austria 104 60 44 164
14 Netherlands England 32 12 20 44 Bosnia-Herzegovina Croatia 55 39 ... 79 61 18 140 Austria Germany 97 67 30 164
15 Norway England 30 14 16 44 France Spain 59 35 ... 75 63 12 138 Germany Turkey 111 45 66 156
16 France Spain 25 19 6 44 Sweden Norway 51 42 ... 70 61 9 131 Spain Greece 97 53 44 150
17 France Germany 29 13 16 42 Portugal Spain 48 45 ... 64 63 1 127 Slovakia Austria 109 36 73 145
18 Brazil Spain 29 12 17 41 England Ireland 58 25 ... 62 58 4 120 Czech Republic Austria 111 33 78 144
19 Germany Turkey 31 10 21 41 Italy England 49 28 ... 68 51 17 119 France Luxembourg 96 47 49 143
20 Spain England 22 16 6 38 Switzerland Germany 44 32 ... 61 54 7 115 France England 102 38 64 140
21 Poland Germany 28 9 19 37 Netherlands Germany 43 32 ... 64 50 14 114 England Ireland 80 55 25 135
22 Germany England 22 14 8 36 France Portugal 39 34 ... 81 28 53 109 Italy England 78 44 34 122
23 Netherlands Germany 21 14 7 35 Germany Poland 41 32 ... 75 34 41 109 Hungary Austria 76 45 31 121
24 Czech Republic Germany 25 9 16 34 France Italy 44 29 ... 55 51 4 106 Spain Italy 68 53 15 121
25 Netherlands Spain 24 10 14 34 Italy Switzerland 39 33 ... 57 48 9 105 Portugal Spain 62 50 12 112
26 Argentina Italy 28 5 23 33 France Luxembourg 52 18 ... 62 41 21 103 Germany Luxembourg 67 44 23 111
27 Croatia Germany 25 8 17 33 Italy Spain 46 24 ... 63 38 25 101 Netherlands Germany 62 48 14 110
28 France Portugal 18 12 6 30 Netherlands England 47 22 ... 69 30 39 99 Ireland Northern Ireland 60 49 11 109
29 Sweden Norway 20 10 10 30 Argentina Italy 37 30 ... 72 27 45 99 Germany England 58 49 9 107
30 Switzerland Italy 17 13 4 30 Croatia Slovenia 37 28 ... 57 39 18 96 Czech Republic Germany 66 33 33 99
31 Brazil Italy 27 3 24 30 England Germany 33 31 ... 66 30 36 96 Netherlands England 70 29 41 99
32 Portugal England 18 11 7 29 Brazil Turkey 35 24 ... 53 42 11 95 Ukraine Russia 71 28 43 99
33 Netherlands Italy 17 12 5 29 Brazil Greece 40 18 ... 56 37 19 93 Slovakia Poland 56 43 13 99
34 Serbia Belgium 26 2 24 28 Brazil Italy 40 17 ... 60 32 28 92 Poland Germany 60 37 23 97
35 Belgium Germany 18 9 9 27 Brazil Germany 37 19 ... 49 43 6 92 Belgium Luxembourg 55 42 13 97
36 Italy Germany 14 13 1 27 Belgium Germany 35 19 ... 54 36 18 90 Denmark Norway 58 38 20 96
37 Hungary Germany 18 8 10 26 Poland Greece 32 22 ... 60 30 30 90 Switzerland Germany 54 38 16 92
38 Belgium Italy 14 11 3 25 England Belgium 29 24 ... 45 44 1 89 France Italy 50 41 9 91
39 Serbia Spain 17 7 10 24 France Germany 39 13 ... 45 44 1 89 Spain Cyprus 57 33 24 90
40 France Luxembourg 19 4 15 23 Sweden Denmark 29 23 ... 55 33 22 88 Sweden Finland 43 42 1 85
41 Belgium Turkey 15 8 7 23 Portugal England 33 18 ... 51 36 15 87 France Greece 53 32 21 85
42 Portugal Italy 14 8 6 22 Montenegro Serbia 30 21 ... 43 42 1 85 Portugal Romania 51 32 19 83
43 Greece England 13 9 4 22 Belgium Luxembourg 30 20 ... 43 40 3 83 Serbia Greece 52 30 22 82
44 Sweden England 16 6 10 22 Romania Hungary 32 17 ... 53 29 24 82 Brazil Malta 52 30 22 82
45 Brazil France 18 3 15 21 Hungary Austria 30 19 ... 49 32 17 81 Croatia Germany 55 26 29 81
46 Serbia Greece 14 7 7 21 Brazil France 33 16 ... 49 30 19 79 England United States 55 24 31 79
47 Denmark Germany 15 6 9 21 Brazil Spain 34 14 ... 48 30 18 78 Denmark Sweden 42 37 5 79
48 Bosnia-Herzegovina Croatia 12 9 3 21 England United States 29 18 ... 39 38 1 77 Ukraine Belarus 51 25 26 76
49 Netherlands Scotland 16 5 11 21 Russia Kazakhstan 36 11 ... 44 33 11 77 France Switzerland 44 32 12 76

50 rows × 24 columns


In [19]:
o=nonloans.groupby('period').apply(getImportExportRank('netted')).unstack(level=0).swaplevel(axis=1).sort_index(level=0,axis=1)
ew = pd.ExcelWriter('../data/output/netted_nonloans.xls', encoding='utf-8')
o.to_excel(ew)
ew.save()
o


Out[19]:
period (1995, 2000] (2000, 2005] ... (2005, 2010] (2010, 2015]
fromCountry toCountry export import net total netted fromCountry toCountry export ... net total netted fromCountry toCountry export import net total netted
0 Scotland England 50 44 6 94 44.0 England Scotland 145 ... 13 415 201.0 England Scotland 205 187 18 392 187.0
1 Portugal Spain 48 31 17 79 31.0 Ukraine Russia 87 ... 14 330 158.0 Croatia Bosnia-Herzegovina 193 166 27 359 166.0
2 Italy Spain 37 31 6 68 31.0 Belgium Netherlands 88 ... 37 295 129.0 Serbia Bosnia-Herzegovina 194 141 53 335 141.0
3 Ukraine Russia 42 29 13 71 29.0 France Belgium 116 ... 4 208 102.0 Slovakia Czech Republic 145 125 20 270 125.0
4 France Belgium 37 26 11 63 26.0 Brazil Portugal 177 ... 118 312 97.0 Greece Cyprus 124 115 9 239 115.0
5 Belgium Netherlands 54 24 30 78 24.0 Slovakia Czech Republic 69 ... 43 235 96.0 Slovenia Austria 206 114 92 320 114.0
6 France England 61 20 41 81 20.0 Greece Cyprus 75 ... 37 195 79.0 Belgium Netherlands 109 100 9 209 100.0
7 Slovakia Czech Republic 25 20 5 45 20.0 France Switzerland 55 ... 21 173 76.0 Brazil Portugal 145 92 53 237 92.0
8 France Spain 25 19 6 44 19.0 Germany Austria 61 ... 58 200 71.0 Serbia Montenegro 97 82 15 179 82.0
9 Switzerland Germany 33 19 14 52 19.0 Argentina Spain 62 ... 89 221 66.0 France Belgium 154 72 82 226 72.0
10 France Switzerland 26 19 7 45 19.0 Portugal Spain 48 ... 12 138 63.0 Spain England 110 68 42 178 68.0
11 France Italy 53 16 37 69 16.0 France England 111 ... 1 127 63.0 Austria Germany 97 67 30 164 67.0
12 Spain England 22 16 6 38 16.0 Sweden Norway 51 ... 9 131 61.0 Portugal Cyprus 101 66 35 167 66.0
13 Norway England 30 14 16 44 14.0 Bosnia-Herzegovina Croatia 55 ... 18 140 61.0 Croatia Slovenia 108 63 45 171 63.0
14 Netherlands Germany 21 14 7 35 14.0 Spain England 61 ... 4 120 58.0 Croatia Austria 104 60 44 164 60.0
15 Germany England 22 14 8 36 14.0 France Spain 59 ... 7 115 54.0 England Ireland 80 55 25 135 55.0
16 Switzerland Italy 17 13 4 30 13.0 France Portugal 39 ... 17 119 51.0 Spain Greece 97 53 44 150 53.0
17 France Germany 29 13 16 42 13.0 Germany Turkey 64 ... 4 106 51.0 Spain Italy 68 53 15 121 53.0
18 Italy Germany 14 13 1 27 13.0 Italy Switzerland 39 ... 14 114 50.0 Portugal Spain 62 50 12 112 50.0
19 France Portugal 18 12 6 30 12.0 Switzerland Germany 44 ... 9 105 48.0 Ireland Northern Ireland 60 49 11 109 49.0
20 Netherlands Italy 17 12 5 29 12.0 Germany Poland 41 ... 57 153 48.0 Germany England 58 49 9 107 49.0
21 Argentina Spain 59 12 47 71 12.0 Netherlands Germany 43 ... 1 89 44.0 Netherlands Germany 62 48 14 110 48.0
22 Netherlands England 32 12 20 44 12.0 England Germany 33 ... 1 89 44.0 France Luxembourg 96 47 49 143 47.0
23 Brazil Spain 29 12 17 41 12.0 Argentina Italy 37 ... 80 168 44.0 Germany Turkey 111 45 66 156 45.0
24 Italy England 35 12 23 47 12.0 France Italy 44 ... 6 92 43.0 Hungary Austria 76 45 31 121 45.0
25 Portugal England 18 11 7 29 11.0 Italy England 49 ... 1 85 42.0 Germany Luxembourg 67 44 23 111 44.0
26 Belgium Italy 14 11 3 25 11.0 Croatia Slovenia 37 ... 11 95 42.0 Italy England 78 44 34 122 44.0
27 Brazil Portugal 59 10 49 69 10.0 Slovenia Austria 81 ... 21 103 41.0 Slovakia Poland 56 43 13 99 43.0
28 Netherlands Spain 24 10 14 34 10.0 England Ireland 58 ... 66 146 40.0 Sweden Finland 43 42 1 85 42.0
29 Sweden Norway 20 10 10 30 10.0 England Belgium 29 ... 3 83 40.0 Belgium Luxembourg 55 42 13 97 42.0
30 Germany Turkey 31 10 21 41 10.0 Brazil Turkey 35 ... 18 96 39.0 France Italy 50 41 9 91 41.0
31 Poland Germany 28 9 19 37 9.0 Italy Spain 46 ... 1 77 38.0 Denmark Norway 58 38 20 96 38.0
32 Greece England 13 9 4 22 9.0 Sweden Denmark 29 ... 64 140 38.0 Switzerland Germany 54 38 16 92 38.0
33 Bosnia-Herzegovina Croatia 12 9 3 21 9.0 Netherlands England 47 ... 25 101 38.0 France England 102 38 64 140 38.0
34 Belgium Germany 18 9 9 27 9.0 Poland Greece 32 ... 19 93 37.0 Denmark Sweden 42 37 5 79 37.0
35 Czech Republic Germany 25 9 16 34 9.0 Montenegro Serbia 30 ... 18 90 36.0 France Portugal 38 37 1 75 37.0
36 Belgium Turkey 15 8 7 23 8.0 Brazil Japan 24 ... 15 87 36.0 Poland Germany 60 37 23 97 37.0
37 Croatia Slovenia 9 8 1 17 8.0 Belgium Luxembourg 30 ... 41 109 34.0 Slovakia Austria 109 36 73 145 36.0
38 Kazakhstan Russia 11 8 3 19 8.0 Brazil Germany 37 ... 22 88 33.0 Serbia Hungary 38 36 2 74 36.0
39 Hungary Germany 18 8 10 26 8.0 Russia Lithuania 27 ... 11 77 33.0 Italy Slovenia 40 35 5 75 35.0
40 Croatia Germany 25 8 17 33 8.0 Denmark Germany 28 ... 11 77 33.0 Czech Republic Austria 111 33 78 144 33.0
41 Slovenia Austria 10 8 2 18 8.0 Belgium Germany 35 ... 28 92 32.0 Czech Republic Germany 66 33 33 99 33.0
42 Portugal Italy 14 8 6 22 8.0 Hungary Austria 30 ... 9 73 32.0 Serbia Macedonia 38 33 5 71 33.0
43 Serbia Greece 14 7 7 21 7.0 England United States 29 ... 17 81 32.0 Greece Italy 35 33 2 68 33.0
44 Belgium Spain 8 7 1 15 7.0 Russia Belarus 21 ... 3 65 31.0 Spain Cyprus 57 33 24 90 33.0
45 Montenegro Serbia 9 7 2 16 7.0 Portugal England 33 ... 2 64 31.0 France Greece 53 32 21 85 32.0
46 Spain Greece 8 7 1 15 7.0 Italy Belgium 22 ... 39 99 30.0 Germany Greece 37 32 5 69 32.0
47 Brazil Japan 8 7 1 15 7.0 Brazil Greece 40 ... 12 72 30.0 Portugal Romania 51 32 19 83 32.0
48 Argentina Mexico 8 7 1 15 7.0 France Luxembourg 52 ... 36 96 30.0 France Switzerland 44 32 12 76 32.0
49 Serbia Spain 17 7 10 24 7.0 Belgium Turkey 27 ... 12 72 30.0 France Germany 32 31 1 63 31.0

50 rows × 28 columns


In [ ]:
o=nonloans[nonloans.feeValue>0].groupby('period').apply(getImportExportRank('netted')).unstack(level=0).swaplevel(axis=1).sort_index(level=0,axis=1)
ew = pd.ExcelWriter('../data/output/paid_netted_nonloans.xls', encoding='utf-8')
o.to_excel(ew)
ew.save()
o

In [21]:
o=nonloans[nonloans.feeValue>0].groupby('period').apply(getImportExportRank('total')).unstack(level=0).swaplevel(axis=1).sort_index(level=0,axis=1)
ew = pd.ExcelWriter('../data/output/paid_total_nonloans.xls', encoding='utf-8')
o.to_excel(ew)
ew.save()
o


Out[21]:
period (1995, 2000] (2000, 2005] ... (2005, 2010] (2010, 2015]
fromCountry toCountry export import net total netted fromCountry toCountry export ... net total netted fromCountry toCountry export import net total netted
0 France England 37 10 27 47 10.0 France England 52 ... 37 109 36.0 Spain England 62 23 39 85 23.0
1 Scotland England 25 15 10 40 15.0 Scotland England 37 ... 11 75 32.0 France England 65 16 49 81 16.0
2 France Italy 24 4 20 28 4.0 Spain England 31 ... 48 66 9.0 Italy England 42 18 24 60 18.0
3 Italy England 23 4 19 27 4.0 Italy England 21 ... 14 56 21.0 Germany England 38 21 17 59 21.0
4 Netherlands England 20 3 17 23 3.0 Argentina Spain 22 ... 36 54 9.0 Spain Italy 34 18 16 52 18.0
5 Germany Italy 10 9 1 19 9.0 Denmark Germany 18 ... 25 41 8.0 Portugal Spain 34 15 19 49 15.0
6 Spain England 11 7 4 18 7.0 France Spain 16 ... 25 39 7.0 Scotland England 42 6 36 48 6.0
7 Germany England 10 7 3 17 7.0 Brazil Germany 19 ... 20 38 9.0 Netherlands England 43 4 39 47 4.0
8 Brazil Italy 16 1 15 17 1.0 Switzerland Germany 18 ... 3 37 17.0 Germany Turkey 42 5 37 47 5.0
9 Netherlands Spain 13 3 10 16 3.0 Netherlands Germany 18 ... 5 35 15.0 Austria Germany 32 8 24 40 8.0
10 Norway England 14 1 13 15 1.0 Ukraine Russia 14 ... 21 33 6.0 France Italy 22 18 4 40 18.0
11 Portugal England 13 2 11 15 2.0 Brazil Portugal 16 ... 28 32 2.0 France Spain 25 11 14 36 11.0
12 Spain France 8 7 1 15 7.0 Italy Spain 14 ... 12 32 10.0 Italy Germany 21 13 8 34 13.0
13 Germany Turkey 12 2 10 14 2.0 Brazil France 18 ... 20 30 5.0 Switzerland Germany 28 6 22 34 6.0
14 Switzerland Germany 9 4 5 13 4.0 Germany England 11 ... 26 28 1.0 Brazil Italy 25 7 18 32 7.0
15 Austria Germany 9 4 5 13 4.0 Belgium France 15 ... 13 27 7.0 Argentina Italy 22 9 13 31 9.0
16 Brazil Spain 10 2 8 12 2.0 Belgium Netherlands 13 ... 7 27 10.0 Portugal England 23 5 18 28 5.0
17 Belgium Germany 10 2 8 12 2.0 Germany Turkey 10 ... 23 27 2.0 Netherlands Germany 19 8 11 27 8.0
18 France Germany 11 1 10 12 1.0 Austria Germany 9 ... 20 26 3.0 England Turkey 20 6 14 26 6.0
19 Croatia Germany 11 1 10 12 1.0 Switzerland France 10 ... 5 25 10.0 France Belgium 17 9 8 26 9.0
20 Argentina Spain 11 1 10 12 1.0 Denmark England 14 ... 11 25 7.0 Spain Germany 14 11 3 25 11.0
21 Netherlands Germany 8 3 5 11 3.0 Belgium England 11 ... 2 24 11.0 Brazil Portugal 17 5 12 22 5.0
22 Brazil Portugal 9 1 8 10 1.0 Portugal Russia 13 ... 3 23 10.0 Portugal Italy 16 6 10 22 6.0
23 Belgium England 8 1 7 9 1.0 Portugal England 12 ... 2 22 10.0 Belgium England 17 4 13 21 4.0
24 Ukraine Russia 5 4 1 9 4.0 Portugal Spain 9 ... 10 22 6.0 France Germany 12 9 3 21 9.0
25 Portugal Spain 7 2 5 9 2.0 Brazil Russia 10 ... 8 22 7.0 Denmark Germany 12 8 4 20 8.0
26 Turkey Spain 7 2 5 9 2.0 Argentina Italy 7 ... 8 22 7.0 Portugal France 13 7 6 20 7.0
27 Germany Scotland 6 2 4 8 2.0 Belgium Germany 8 ... 6 22 8.0 Brazil Ukraine 12 8 4 20 8.0
28 Bulgaria Germany 7 1 6 8 1.0 Greece England 6 ... 13 21 4.0 Denmark Netherlands 13 6 7 19 6.0
29 Sweden England 7 1 6 8 1.0 France Italy 6 ... 3 21 9.0 France Turkey 14 5 9 19 5.0
30 Switzerland England 7 1 6 8 1.0 Poland Germany 10 ... 5 21 8.0 Netherlands Belgium 14 4 10 18 4.0
31 Denmark Germany 7 1 6 8 1.0 Czech Republic Germany 9 ... 17 21 2.0 Argentina Spain 14 3 11 17 3.0
32 Greece England 6 1 5 7 1.0 Sweden Netherlands 9 ... 16 20 2.0 Switzerland Italy 12 5 7 17 5.0
33 Romania Spain 6 1 5 7 1.0 Belgium Turkey 8 ... 6 20 7.0 Netherlands Italy 15 2 13 17 2.0
34 Greece Italy 4 3 1 7 3.0 Brazil Italy 9 ... 15 19 2.0 England Russia 9 7 2 16 7.0
35 Denmark England 6 1 5 7 1.0 Romania Ukraine 8 ... 7 19 6.0 Spain Turkey 13 3 10 16 3.0
36 Croatia Spain 5 1 4 6 1.0 Germany Italy 5 ... 17 19 1.0 Greece Germany 12 4 8 16 4.0
37 Spain Germany 4 2 2 6 2.0 Denmark Sweden 5 ... 11 17 3.0 Poland Germany 11 4 7 15 4.0
38 Portugal Italy 4 2 2 6 2.0 Cyprus Greece 7 ... 13 17 2.0 Denmark England 10 4 6 14 4.0
39 Netherlands Italy 4 2 2 6 2.0 Germany Spain 5 ... 10 16 3.0 Portugal Turkey 13 1 12 14 1.0
40 Denmark Netherlands 3 2 1 5 2.0 Italy Greece 5 ... 10 16 3.0 Norway Germany 13 1 12 14 1.0
41 Turkey England 3 2 1 5 2.0 France Turkey 5 ... 10 16 3.0 Brazil Russia 9 4 5 13 4.0
42 Wales England 3 2 1 5 2.0 Portugal France 5 ... 4 16 6.0 Poland Russia 12 1 11 13 1.0
43 Greece Spain 3 2 1 5 2.0 Slovakia Russia 7 ... 5 15 5.0 Russia Turkey 9 4 5 13 4.0
44 Italy Turkey 4 1 3 5 1.0 Romania Turkey 7 ... 9 15 3.0 Portugal Russia 10 3 7 13 3.0
45 Austria England 4 1 3 5 1.0 Ireland England 7 ... 6 14 4.0 Romania Italy 10 3 7 13 3.0
46 Serbia Bulgaria 3 1 2 4 1.0 France Greece 6 ... 6 14 4.0 France Russia 9 3 6 12 3.0
47 Italy Scotland 3 1 2 4 1.0 Norway Germany 4 ... 6 14 4.0 Belgium Germany 9 3 6 12 3.0
48 Turkey France 2 1 1 3 1.0 Italy Russia 5 ... 6 14 4.0 Sweden Italy 10 2 8 12 2.0
49 Israel England 2 1 1 3 1.0 Romania Russia 5 ... 8 14 3.0 Greece Italy 10 2 8 12 2.0

50 rows × 28 columns


In [4]:
countryInfo.groupby('marketTier').count()


Out[4]:
federation
marketTier
1.0 5
2.0 11
3.0 23
4.0 30

In [9]:
s=transfers[transfers.season>2000].groupby(['season','toCountry']).sum()['feeValue'].unstack()
s[s.sum().sort_values(ascending=False)[:10].index]


Out[9]:
toCountry England Italy Spain Germany France Russia Turkey Portugal Netherlands Ukraine
season
2001.0 6.558950e+08 689095000.0 273150000.0 193198000.0 146180000.0 13370000.0 23455000.0 39600000.0 52810000.0 3190000.0
2002.0 3.455440e+08 311425000.0 149820000.0 121070000.0 67270000.0 21305000.0 42580000.0 15330000.0 37531000.0 8300000.0
2003.0 4.458020e+08 172975000.0 142875000.0 87620000.0 107480000.0 53690000.0 30365000.0 20880000.0 30800000.0 43625000.0
2004.0 5.259750e+08 215060000.0 232245000.0 90285000.0 142648000.0 97755000.0 44135000.0 54875000.0 29569000.0 43303000.0
2005.0 5.575570e+08 189713000.0 233820000.0 113461000.0 178920000.0 135935000.0 43549000.0 36225000.0 38480000.0 25094000.0
2006.0 6.286610e+08 270946000.0 391769000.0 156355000.0 213345000.0 101375000.0 64710000.0 23750000.0 64510000.0 29450000.0
2007.0 1.073855e+09 451994000.0 569436000.0 301535000.0 258850000.0 129350000.0 49330000.0 73155000.0 112385000.0 96010000.0
2008.0 9.055010e+08 616954000.0 411990000.0 190010000.0 267740000.0 143790000.0 82440000.0 87149000.0 95650000.0 47258000.0
2009.0 6.930900e+08 574033000.0 511447000.0 257480000.0 272478000.0 126068000.0 88097000.0 81536000.0 67530000.0 62985000.0
2010.0 7.649780e+08 496378000.0 314340000.0 223765000.0 159565000.0 228108000.0 114045000.0 88240000.0 44275000.0 123702000.0
2011.0 7.241870e+08 660713000.0 400823000.0 229220000.0 259590000.0 238800000.0 129130000.0 117738000.0 71383000.0 77655000.0
2012.0 8.559370e+08 576965000.0 161160000.0 312680000.0 246750000.0 358690000.0 120509000.0 53363000.0 49511000.0 76370000.0
2013.0 9.681510e+08 578840000.0 446385000.0 320315000.0 420680000.0 339767000.0 118157000.0 107855000.0 41785000.0 131070000.0
2014.0 1.320913e+09 441393000.0 547772000.0 401350000.0 173060000.0 90307000.0 86958000.0 116581000.0 43145000.0 24350000.0
2015.0 1.595048e+09 670339000.0 615110000.0 501453000.0 351030000.0 37568000.0 112022000.0 89228000.0 63065000.0 11750000.0

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_q.csv',index_col=False, warn_bad_lines =True,error_bad_lines=False)
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']

countryInfo=pd.read_excel('../data/reference/countries.xls').set_index('country')


/Users/sunkevin/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2871: DtypeWarning: Columns (0,38,40,41,45,47,49,55) 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 (40,45,47,51) 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)

In [305]:
countryInfo=pd.read_excel('../data/reference/countries.xls').set_index('country')

In [37]:
pd.Series(np.where(transfers.id==transfers.id.shift(1),transfers.mv-transfers.mv.shift(1).fillna(0),np.nan))


Out[37]:
0              NaN
1         100000.0
2          50000.0
3         -50000.0
4              NaN
5              NaN
6              NaN
7              NaN
8              NaN
9              0.0
10             0.0
11        600000.0
12        500000.0
13             0.0
14             0.0
15        750000.0
16        500000.0
17             0.0
18             NaN
19             NaN
20             NaN
21             NaN
22             NaN
23        225000.0
24             0.0
25             0.0
26             NaN
27             NaN
28             NaN
29             NaN
            ...   
350609         NaN
350610         NaN
350611         NaN
350612         NaN
350613         NaN
350614         NaN
350615         NaN
350616         NaN
350617         0.0
350618         0.0
350619         0.0
350620         NaN
350621         NaN
350622         NaN
350623         NaN
350624         NaN
350625         NaN
350626         NaN
350627         NaN
350628         NaN
350629         NaN
350630         NaN
350631         NaN
350632         NaN
350633         NaN
350634         NaN
350635         NaN
350636         NaN
350637         NaN
350638         NaN
dtype: float64

In [54]:
transfers=pd.read_csv('../data/merged/transfers_q.csv',index_col=False, warn_bad_lines =True,error_bad_lines=False)

In [55]:
transfers.drop_duplicates('id')[['mv','feeValue']].plot.scatter('mv','feeValue',figsize=(10,10))


Out[55]:
<matplotlib.axes._subplots.AxesSubplot at 0x1108c7c90>
/Users/sunkevin/anaconda/lib/python2.7/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):

In [36]:
s=transfers.drop_duplicates('id')
t=(s['mv']/s['feeValue'])
pd.Series(np.where((t!=float("Infinity")),t,np.nan)).mean()


Out[36]:
2.6886234748153512