In [112]:
def payingClubsVsFreeOnlyClubs(t):
    return DataFrame({'payingClubs': t[(t.feeValue>0)&(t.season==2015)]['toTeamId'].drop_duplicates().count(),
                      'allClubs': t[(t.season==2015)]['toTeamId'].drop_duplicates().count()},index=[0])

PayingComparison = nonloans[nonloans.toLeague.isin(leagueTables.league.drop_duplicates())].groupby('toLeague').apply(payingClubsVsFreeOnlyClubs).reset_index().drop('level_1',axis=1).set_index('toLeague')
PayingComparison['payingRatio']=PayingComparison['payingClubs']/PayingComparison['allClubs']
PayingComparison.sort_values('payingRatio')


Out[112]:
allClubs payingClubs payingRatio
toLeague
LI1 8 0 0.000000
LET1 8 0 0.000000
FI1 12 0 0.000000
FARO 5 0 0.000000
EST1 9 0 0.000000
LUX1 14 0 0.000000
GEO1 16 0 0.000000
MAZ1 9 0 0.000000
NIR1 12 0 0.000000
WAL1 5 0 0.000000
AZ1 10 0 0.000000
ARM1 8 0 0.000000
ALB1 10 0 0.000000
MNE1 12 0 0.000000
IR1 12 0 0.000000
BOS1 16 1 0.062500
WER1 15 1 0.066667
ZYP1 14 1 0.071429
KAS1 12 1 0.083333
MAL1 12 1 0.083333
IS1 11 1 0.090909
MOL1 10 1 0.100000
UKR1 14 2 0.142857
SLO1 12 2 0.166667
SC1 12 2 0.166667
TS1 16 3 0.187500
SE1 16 3 0.187500
KR1 10 2 0.200000
SL1 10 2 0.200000
UNG1 12 3 0.250000
SER1 16 4 0.250000
ISR1 14 4 0.285714
BU1 10 3 0.300000
NO1 16 5 0.312500
RO1 14 5 0.357143
MLS1 20 8 0.400000
PO1 18 8 0.444444
GR1 16 8 0.500000
DK1 12 6 0.500000
A1 10 5 0.500000
RU1 16 10 0.625000
BE1 16 10 0.625000
C1 10 7 0.700000
NL1 18 13 0.722222
PL1 16 12 0.750000
FR1 20 17 0.850000
ES1 20 17 0.850000
TR1 18 17 0.944444
IT1 20 19 0.950000
GB1 20 20 1.000000
L1 18 18 1.000000

In [3]:
def sellingClubsVsFreeOnlyClubs(t):
    return DataFrame({'sellingClubs': t[(t.feeValue>0)&(t.season==2015)]['fromTeamId'].drop_duplicates().count(),
                      'allClubs': t[(t.season==2015)]['fromTeamId'].drop_duplicates().count()},index=[0])

PayingComparison = nonloans[nonloans.fromLeague.isin(leagueTables.league.drop_duplicates())].groupby('fromLeague').apply(sellingClubsVsFreeOnlyClubs).reset_index().drop('level_1',axis=1).set_index('fromLeague')
PayingComparison['sellingRatio']=PayingComparison['sellingClubs']/PayingComparison['allClubs']
PayingComparison.sort_values('sellingRatio')


Out[3]:
allClubs sellingClubs sellingRatio
fromLeague
EST1 8 0 0.000000
IR1 12 0 0.000000
LUX1 14 0 0.000000
MAZ1 9 0 0.000000
FARO 6 0 0.000000
LET1 5 0 0.000000
MNE1 12 0 0.000000
KAS1 12 0 0.000000
NIR1 9 0 0.000000
WAL1 4 0 0.000000
AZ1 10 0 0.000000
ARM1 8 0 0.000000
MOL1 10 0 0.000000
MAL1 12 1 0.083333
ALB1 10 1 0.100000
GEO1 15 2 0.133333
WER1 14 2 0.142857
ZYP1 14 2 0.142857
FI1 12 2 0.166667
IS1 10 2 0.200000
MLS1 20 5 0.250000
SLO1 12 3 0.250000
LI1 8 2 0.250000
BOS1 16 4 0.250000
ISR1 14 4 0.285714
TS1 16 5 0.312500
SC1 12 5 0.416667
UNG1 12 5 0.416667
BU1 10 5 0.500000
SL1 10 5 0.500000
SE1 16 8 0.500000
SER1 16 8 0.500000
UKR1 14 7 0.500000
RU1 16 9 0.562500
ES1 20 12 0.600000
RO1 14 9 0.642857
TR1 18 12 0.666667
NO1 16 11 0.687500
A1 10 7 0.700000
PL1 16 12 0.750000
GR1 16 12 0.750000
BE1 16 12 0.750000
PO1 18 14 0.777778
KR1 10 8 0.800000
DK1 12 10 0.833333
L1 18 16 0.888889
C1 10 9 0.900000
NL1 18 17 0.944444
FR1 20 19 0.950000
IT1 20 19 0.950000
GB1 20 20 1.000000

In [2]:
def transfercount(club):
    return club

clubSeasonInOut=DataFrame({'transfers out': nonloans.groupby(['fromTeamId','season']).count()['id'],
    'transfers in':nonloans.groupby(['toTeamId','season']).count()['id']}).fillna(0).reset_index().rename(columns={'level_0':'clubId','level_1':'season'})

def topTeams(league):
    t= league.groupby('clubId').agg({'points':'sum','clubName':'first','transfers in': 'mean','transfers out': 'mean','goalDiff':'sum','goalsFor':'sum','goalsAgainst':'sum','season':'count','rank': 'mean'}).sort_values('points',ascending=False)
    t['invRank']=league['rank'].max()-t['rank']
    t['scaleRank']=t['rank']/league['rank'].max()
    return t

RO1=leagueTables.merge(clubSeasonInOut).groupby('league').apply(topTeams).ix['RO1']

stabilityVsPerf=leagueTables[leagueTables['season'].between(2010,2015)].merge(clubSeasonInOut).groupby('league').apply(topTeams) #.ix['GR1'].sort_values('goalDiff').plot.scatter(x='transfers in',y='points')
stabilityVsPerf=stabilityVsPerf.join(nonloans[nonloans['season'].between(2010,2015)].rename(columns={'fromLeague':'league','fromTeamId':'clubId'}).groupby(['league','clubId'])[['duration']].mean())
stabilityVsPerf=stabilityVsPerf.join(transfers[transfers['season'].between(2010,2015)].rename(columns={'fromLeague':'league','fromTeamId':'clubId'}).groupby(['league','clubId'])[['durationWithLoans']].mean())

stabilityVsPerf=stabilityVsPerf.reset_index().merge(club_coeff,how='left',right_on='clubId',left_on='clubId',suffixes=('','_uefa'))

countryLeagueMap=nonloans[['fromCountry','fromLeague']].drop_duplicates().rename(columns={'fromLeague':'league','fromCountry':'Country'})

stabilityVsPerf=stabilityVsPerf.merge(countryLeagueMap,how='left',left_on='league',right_on='league').merge(countryInfo,how='left',left_on='Country',right_index=True)

ew = pd.ExcelWriter('../data/analysis/stability_performance.xls', encoding='utf-8')
stabilityVsPerf.to_excel(ew, merge_cells=False)
ew.save()

stabilityVsPerf


Out[2]:
league clubId transfers out points goalsAgainst season goalDiff transfers in clubName rank ... GDP 2013 GDP 2014 Unemployment Corruption Population Growth % federation marketTier Corruption Rank Bribe %
0 A1 409 11.166667 435 210 6 274 12.500000 RB Salzburg 1.333333 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
1 A1 170 8.500000 366 231 6 127 8.500000 Rapid Vienna 2.666667 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
2 A1 14 10.666667 352 255 6 114 11.333333 Austria Vienna 3.666667 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
3 A1 122 11.333333 319 266 6 48 11.666667 Sturm Graz 4.000000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
4 A1 266 10.500000 281 304 6 -9 10.833333 SV Ried 5.833333 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
5 A1 503 9.600000 216 299 5 -65 11.600000 Admira Wacker 6.800000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
6 A1 17444 12.200000 187 326 5 -144 12.400000 Wiener Neustadt 8.200000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
7 A1 4441 8.500000 183 205 4 -25 9.250000 Wolfsberger AC 5.750000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
8 A1 2444 7.500000 160 232 4 -70 8.500000 FC Wacker 7.750000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
9 A1 856 4.750000 143 236 4 -90 7.000000 SV Mattersburg 9.000000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
10 A1 10131 10.333333 126 192 3 -36 13.000000 SV Grödig 7.000000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
11 A1 3551 2.500000 99 98 2 -9 8.500000 SCR Altach 5.500000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
12 A1 2394 17.500000 61 125 2 -62 16.500000 SV Kapfenberg 9.000000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
13 A1 413 19.000000 19 75 1 -53 20.000000 LASK 10.000000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
14 ALB1 12469 4.333333 407 130 6 193 5.333333 KF Skënderbeu 1.000000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
15 ALB1 2049 6.000000 314 158 6 67 5.833333 KF Tirana 4.666667 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
16 ALB1 3739 2.166667 292 199 6 24 2.166667 KF Teuta Durrës 4.666667 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
17 ALB1 12460 5.833333 285 202 6 56 6.000000 FC Flamurtari 5.166667 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
18 ALB1 22140 1.500000 284 198 6 21 2.166667 KF Laçi 5.666667 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
19 ALB1 8671 5.000000 254 205 6 10 4.166667 KF Vllaznia 6.000000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
20 ALB1 27116 4.250000 247 111 4 84 5.750000 FK Kukësi 2.250000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
21 ALB1 4040 6.333333 200 71 3 55 8.333333 FK Partizani 3.333333 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
22 ALB1 21234 1.600000 167 221 5 -58 3.400000 FK Bylis Ballsh 8.800000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
23 ALB1 12462 5.750000 143 158 4 -30 6.000000 KF Kastrioti 7.750000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
24 ALB1 739 4.333333 113 105 3 -13 4.333333 KS Besa Kavajë 9.666667 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
25 ALB1 12468 2.333333 105 129 3 -30 1.333333 KF Shkumbini Peqin 9.666667 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
26 ALB1 588 4.500000 55 91 2 -26 4.000000 Dinamo Tiranë 12.000000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
27 ALB1 12448 1.000000 34 86 2 -43 1.000000 KF Apolonia 13.000000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
28 ALB1 6983 3.500000 29 153 2 -104 5.500000 KF Elbasani 11.000000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
29 ALB1 21786 2.000000 27 32 1 -10 5.000000 FC Kamza 11.000000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1008 WER1 6131 3.000000 152 239 6 -90 2.666667 Dinamo Brest 10.166667 ... 71.710 76.139 1.0 32.0 9481000.0 0.00 UEFA 3.0 NaN NaN
1009 WER1 6423 2.500000 91 163 4 -72 3.750000 Slavia 10.500000 ... 71.710 76.139 1.0 32.0 9481000.0 0.00 UEFA 3.0 NaN NaN
1010 WER1 17959 3.666667 77 106 3 -40 4.666667 Vitebsk 10.333333 ... 71.710 76.139 1.0 32.0 9481000.0 0.00 UEFA 3.0 NaN NaN
1011 WER1 4394 4.333333 67 109 3 -49 3.333333 Dnepr Mogilev 11.333333 ... 71.710 76.139 1.0 32.0 9481000.0 0.00 UEFA 3.0 NaN NaN
1012 WER1 27238 3.666667 67 80 3 -25 4.333333 FK Slutsk 11.333333 ... 71.710 76.139 1.0 32.0 9481000.0 0.00 UEFA 3.0 NaN NaN
1013 WER1 19726 2.500000 62 54 2 -8 4.500000 Granit 8.000000 ... 71.710 76.139 1.0 32.0 9481000.0 0.00 UEFA 3.0 NaN NaN
1014 WER1 36755 1.000000 30 23 1 3 4.000000 Isloch 2.000000 ... 71.710 76.139 1.0 32.0 9481000.0 0.00 UEFA 3.0 NaN NaN
1015 WER1 46070 0.000000 28 21 1 -1 4.000000 Krumkachi 4.000000 ... 71.710 76.139 1.0 32.0 9481000.0 0.00 UEFA 3.0 NaN NaN
1016 WER1 29525 1.000000 24 17 1 2 5.000000 Gorodeya 8.000000 ... 71.710 76.139 1.0 32.0 9481000.0 0.00 UEFA 3.0 NaN NaN
1017 ZYP1 2784 11.333333 351 91 6 221 11.166667 APOEL Nicosia 1.666667 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1018 ZYP1 829 14.000000 295 122 6 136 13.000000 Omonia Nikosia 3.333333 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1019 ZYP1 3899 15.166667 285 144 6 115 13.666667 Anor. Famagusta 3.833333 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1020 ZYP1 2156 15.333333 276 140 6 104 14.333333 AEK Larnaca 4.333333 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1021 ZYP1 429 15.000000 268 169 6 72 14.166667 Apol. Limassol 4.500000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1022 ZYP1 786 18.166667 267 143 6 67 15.500000 AEL Limassol 5.166667 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1023 ZYP1 4590 17.666667 153 208 6 -62 17.000000 Ethnikos 9.833333 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1024 ZYP1 18945 19.400000 149 188 5 -58 19.200000 Nea Salamis 7.800000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1025 ZYP1 24326 23.000000 148 184 5 -46 21.000000 Ermis Aradippou 9.200000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1026 ZYP1 840 18.600000 135 176 5 -53 16.600000 En. Paralimni 9.800000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1027 ZYP1 3393 22.400000 122 219 5 -90 20.600000 D. Katokopias 10.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1028 ZYP1 1402 17.000000 93 119 3 -13 17.333333 Olympiakos N. 8.666667 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1029 ZYP1 8701 18.750000 90 204 4 -95 17.000000 Alki Larnaca 10.500000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1030 ZYP1 10586 13.000000 78 106 3 -21 16.333333 Aris Limassol 10.666667 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1031 ZYP1 7475 28.000000 41 101 2 -51 27.000000 AE Pafos 13.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1032 ZYP1 10816 13.666667 30 165 3 -112 17.000000 Agia Napa 12.333333 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1033 ZYP1 45457 13.000000 27 47 1 -12 15.000000 Pafos FC 10.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1034 ZYP1 26129 7.000000 21 64 1 -37 29.000000 AEK Kouklia 12.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1035 ZYP1 8554 30.000000 19 47 1 -23 24.000000 APOP Kinyras 14.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1036 ZYP1 30606 5.000000 16 26 1 -13 12.000000 Othellos Athienou 11.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
1037 ZYP1 6043 9.000000 11 45 1 -29 20.000000 Anagennisi Dery 13.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0

1038 rows × 55 columns


In [2]:
def transfercount(club):
    return club

clubSeasonInOut=DataFrame({'transfers out': transfers.groupby(['fromTeamId','season']).count()['id'],
    'transfers in':transfers.groupby(['toTeamId','season']).count()['id']}).fillna(0).reset_index().rename(columns={'level_0':'clubId','level_1':'season'})

def topTeams(league):
    t= league.groupby('clubId').agg({'points':'sum','clubName':'first','transfers in': 'mean','transfers out': 'mean','goalDiff':'sum','goalsFor':'sum','goalsAgainst':'sum','rank': 'mean'}).sort_values('points',ascending=False)
    t['invRank']=league['rank'].max()-t['rank']
    t['scaleRank']=t['rank']/league['rank'].max()
    return t

RO1=leagueTables.merge(clubSeasonInOut).groupby('league').apply(topTeams).ix['RO1']

stabilityVsPerf2=leagueTables[leagueTables.season>2005].merge(clubSeasonInOut).groupby(['league','season']).apply(topTeams) #.ix['GR1'].sort_values('goalDiff').plot.scatter(x='transfers in',y='points')
#stabilityVsPerf2=stabilityVsPerf2.join(nonloans[nonloans['season'].between(2010,2015)].rename(columns={'fromLeague':'league','fromTeamId':'clubId'}).groupby(['league','season','clubId'])[['duration']].mean())
#stabilityVsPerf2=stabilityVsPerf2.join(transfers[transfers['season'].between(2010,2015)].rename(columns={'fromLeague':'league','fromTeamId':'clubId'}).groupby(['league','season','clubId'])[['durationWithLoans']].mean())

stabilityVsPerf2=stabilityVsPerf2.reset_index().merge(club_coeff,how='left',right_on='clubId',left_on='clubId',suffixes=('','_uefa'))

countryLeagueMap=transfers[['fromCountry','fromLeague']].drop_duplicates().rename(columns={'fromLeague':'league','fromCountry':'Country'})

stabilityVsPerf2=stabilityVsPerf2.merge(countryLeagueMap,how='left',left_on='league',right_on='league').merge(countryInfo,how='left',left_on='Country',right_index=True)

ew = pd.ExcelWriter('../data/analysis/stability_performance.xls', encoding='utf-8')
stabilityVsPerf2.to_excel(ew, merge_cells=False)
ew.save()

stabilityVsPerf2


Out[2]:
league season clubId transfers out points goalsAgainst goalDiff transfers in clubName rank ... GDP 2013 GDP 2014 Unemployment Corruption Population Growth % federation marketTier Corruption Rank Bribe %
0 A1 2006 409 19.0 75 25 47 14.0 RB Salzburg 1 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
1 A1 2006 266 11.0 56 42 5 15.0 SV Ried 2 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
2 A1 2006 856 9.0 55 58 3 6.0 SV Mattersburg 3 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
3 A1 2006 122 4.0 54 40 0 10.0 Sturm Graz 7 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
4 A1 2006 170 9.0 52 49 6 11.0 Rapid Vienna 4 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
5 A1 2006 935 18.0 52 41 6 14.0 FC Pasching 5 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
6 A1 2006 14 19.0 45 43 0 14.0 Austria Vienna 6 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
7 A1 2006 3551 3.0 38 64 -19 10.0 SCR Altach 8 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
8 A1 2006 316 14.0 34 67 -24 14.0 Grazer AK 10 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
9 A1 2006 2444 7.0 34 64 -24 6.0 Wacker Tirol 9 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
10 A1 2007 170 10.0 69 36 33 8.0 Rapid Vienna 1 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
11 A1 2007 409 7.0 63 42 21 6.0 RB Salzburg 2 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
12 A1 2007 14 8.0 58 33 13 10.0 Austria Vienna 3 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
13 A1 2007 122 15.0 56 41 19 12.0 Sturm Graz 4 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
14 A1 2007 413 10.0 53 47 7 17.0 LASK 6 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
15 A1 2007 856 5.0 53 43 12 7.0 SV Mattersburg 5 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
16 A1 2007 266 15.0 38 53 -15 12.0 SV Ried 7 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
17 A1 2007 3551 11.0 36 64 -27 14.0 SCR Altach 8 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
18 A1 2007 11609 2.0 33 58 -32 31.0 Austria Kärnten 9 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
19 A1 2007 2444 13.0 29 63 -31 10.0 FC Wacker 10 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
20 A1 2008 409 12.0 74 50 36 10.0 RB Salzburg 1 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
21 A1 2008 170 7.0 70 43 46 9.0 Rapid Vienna 2 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
22 A1 2008 14 13.0 62 46 13 11.0 Austria Vienna 3 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
23 A1 2008 122 14.0 60 45 23 12.0 Sturm Graz 4 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
24 A1 2008 266 17.0 60 38 20 19.0 SV Ried 5 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
25 A1 2008 11609 16.0 41 57 -10 16.0 Austria Kärnten 6 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
26 A1 2008 413 10.0 37 67 -32 15.0 LASK 7 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
27 A1 2008 2394 8.0 36 81 -33 15.0 SV Kapfenberg 8 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
28 A1 2008 856 8.0 33 71 -29 9.0 SV Mattersburg 9 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
29 A1 2008 3551 17.0 30 90 -34 19.0 SCR Altach 10 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
6103 ZYP1 2013 840 21.0 22 45 -16 22.0 En. Paralimni 11 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6104 ZYP1 2013 26129 7.0 21 64 -37 29.0 AEK Kouklia 12 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6105 ZYP1 2013 10586 15.0 20 40 -11 20.0 Aris Limassol 13 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6106 ZYP1 2013 8701 20.0 2 78 -64 14.0 Alki Larnaca 14 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6107 ZYP1 2014 429 20.0 48 26 23 17.0 Apol. Limassol 1 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6108 ZYP1 2014 2784 14.0 46 13 21 11.0 APOEL Nicosia 2 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6109 ZYP1 2014 829 26.0 39 22 10 19.0 Omonia Nikosia 3 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6110 ZYP1 2014 2156 15.0 39 23 18 16.0 AEK Larnaca 4 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6111 ZYP1 2014 3899 14.0 38 22 10 13.0 Anor. Famagusta 5 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6112 ZYP1 2014 24326 26.0 35 28 1 21.0 Ermis Aradippou 6 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6113 ZYP1 2014 786 19.0 30 26 7 19.0 AEL Limassol 7 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6114 ZYP1 2014 4590 23.0 22 37 -19 21.0 Ethnikos 8 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6115 ZYP1 2014 18945 25.0 19 29 -13 24.0 Nea Salamis 9 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6116 ZYP1 2014 10816 19.0 16 42 -21 25.0 Agia Napa 10 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6117 ZYP1 2014 30606 5.0 16 26 -13 14.0 Othellos Athienou 11 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6118 ZYP1 2014 3393 31.0 14 38 -24 23.0 D. Katokopias 12 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6119 ZYP1 2015 2784 17.0 62 18 54 17.0 APOEL Nicosia 1 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6120 ZYP1 2015 2156 16.0 61 17 30 12.0 AEK Larnaca 2 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6121 ZYP1 2015 3899 16.0 52 22 26 14.0 Anor. Famagusta 3 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6122 ZYP1 2015 429 17.0 49 24 17 12.0 Apol. Limassol 5 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6123 ZYP1 2015 829 20.0 49 24 22 16.0 Omonia Nikosia 4 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6124 ZYP1 2015 18945 19.0 33 52 -15 20.0 Nea Salamis 6 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6125 ZYP1 2015 786 20.0 31 32 -10 19.0 AEL Limassol 8 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6126 ZYP1 2015 10586 14.0 31 31 -2 19.0 Aris Limassol 7 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6127 ZYP1 2015 3393 20.0 30 41 -10 19.0 D. Katokopias 9 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6128 ZYP1 2015 45457 14.0 27 47 -12 17.0 Pafos FC 10 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6129 ZYP1 2015 4590 13.0 24 43 -16 19.0 Ethnikos 11 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6130 ZYP1 2015 24326 24.0 24 40 -18 24.0 Ermis Aradippou 12 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6131 ZYP1 2015 840 14.0 20 47 -19 16.0 En. Paralimni 13 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
6132 ZYP1 2015 10816 14.0 6 64 -47 15.0 Agia Napa 14 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0

6133 rows × 53 columns


In [13]:
stabilityVsPerf2['goalDiffPos']=stabilityVsPerf2['transfers in']>20
stabilityVsPerf2['lots of transfers']=stabilityVsPerf2['transfers in']>20

x=stabilityVsPerf2[stabilityVsPerf2['transfers in']>20].groupby('goalDiff')['clubId'].mean()

y=stabilityVsPerf2.groupby('lots of transfers')['goalDiff'].mean()

y

stabilityVsPerf2['goalDiff'].mean()

#stabilityVsPerf2[(stabilityVsPerf2['transfers in']>20)][['clubId','Country','clubName']].drop_duplicates().groupby('Country').count()['clubId'].sort_values() #.plot.pie()


Out[13]:
0.3792597423773031

In [69]:
import math
stabilityVsPerf2['third']=stabilityVsPerf2['scaleRank']<0.5 #.apply(lambda x:math.floor(x*10))

stabilityVsPerf2.groupby('third')['transfers in'].mean() #.plot.line()


Out[69]:
third
False    13.202067
True     11.318611
Name: transfers in, dtype: float64

In [8]:
import math

def aggregate(t):
    s= t[t['transfers in'].isin(t['transfers in'].describe()[['max','min']])][['clubName','season','transfers in','rank','scaleRank','invRank']]
    s['diff']=s['transfers in'].max()-s['transfers in'].min()
    return s

z=stabilityVsPerf2.groupby('clubId').apply(aggregate)
z[z['diff']>20].sort_values('diff',ascending=False)


Out[8]:
clubName season transfers in rank scaleRank invRank diff
clubId
130 2319 Parma 2006 13.0 12 0.600000 8 71.0
2452 Parma 2013 84.0 6 0.300000 14 71.0
3216 5347 Mersin IY 2012 35.0 18 1.000000 0 33.0
5401 Mersin IY 2015 2.0 18 1.000000 0 33.0
5862 5075 ND Gorica 2013 36.0 4 0.400000 6 32.0
5056 ND Gorica 2011 4.0 5 0.500000 5 32.0
10442 4320 Unirea Urziceni 2009 6.0 2 0.111111 16 29.0
4352 Unirea Urziceni 2010 35.0 17 0.944444 1 29.0
3544 4961 Smederevo 2012 38.0 16 1.000000 0 28.0
4908 Smederevo 2009 10.0 11 0.687500 5 28.0
11141 3348 Toronto 2006 35.0 13 1.000000 0 27.0
3471 Toronto 2015 8.0 2 0.200000 8 27.0
4078 3473 Montreal 2015 9.0 4 0.400000 6 27.0
3423 Montreal 2011 36.0 12 0.631579 7 27.0
868 5329 Ankaragücü 2011 13.0 18 1.000000 0 26.0
5306 Ankaragücü 2010 39.0 13 0.722222 5 26.0
5286 Ankaragücü 2009 39.0 12 0.666667 6 26.0
4959 4425 Otelul Galati 2014 35.0 17 0.944444 1 25.0
5228 2996 Atlantas 2011 30.0 8 0.800000 2 25.0
2966 Atlantas 2007 5.0 5 0.625000 3 25.0
4959 4337 Otelul Galati 2010 10.0 1 0.055556 17 25.0
4529 5216 Dunajska Streda 2015 14.0 7 0.583333 5 24.0
10314 2645 Karlovac 1919 2011 37.0 15 0.937500 1 24.0
2604 Karlovac 1919 2009 13.0 6 0.375000 10 24.0
172 379 RSC Charleroi 2010 30.0 16 1.000000 0 24.0
433 RSC Charleroi 2014 6.0 6 0.375000 10 24.0
2293 5310 Konyaspor 2010 37.0 17 0.944444 1 24.0
4529 5134 Dunajska Streda 2008 38.0 9 0.750000 3 24.0
2293 5253 Konyaspor 2007 13.0 14 0.777778 4 24.0
5378 5759 Vasas SC 2008 13.0 10 0.625000 6 23.0
16704 4571 Krasnodar 2015 8.0 4 0.250000 12 23.0
4512 Krasnodar 2010 31.0 8 0.500000 8 23.0
5378 5812 Vasas SC 2011 36.0 15 0.937500 1 23.0
5220 1990 Ergotelis 2014 27.0 16 0.888889 2 22.0
599 2596 Varteks 2008 8.0 10 0.833333 2 22.0
2646 NK Varazdin 2011 30.0 16 1.000000 0 22.0
5220 1916 Ergotelis 2010 5.0 8 0.500000 8 22.0
4277 2049 Drogheda United 2010 30.0 9 0.900000 1 22.0
23560 3009 Kruoja 2013 24.0 2 0.200000 8 22.0
2700 4522 Anzhi 2012 8.0 3 0.187500 13 22.0
4277 2014 Drogheda United 2007 8.0 8 0.666667 4 22.0
6621 4909 Cukaricki 2009 29.0 13 0.812500 3 22.0
4980 Cukaricki 2014 7.0 3 0.187500 13 22.0
23560 2976 Kruoja 2008 2.0 8 1.000000 0 22.0
2700 4551 Anzhi 2013 30.0 16 1.000000 0 22.0
24197 486 Rudar Prijedor 2009 8.0 10 0.625000 6 21.0
82 2750 VfL Wolfsburg 2009 5.0 8 0.444444 10 21.0
6163 5202 FK Senica 2014 11.0 5 0.416667 7 21.0
5143 FK Senica 2009 32.0 6 0.500000 6 21.0
82 2786 VfL Wolfsburg 2011 26.0 8 0.444444 10 21.0
2782 2934 Ventspils 2013 2.0 1 0.100000 9 21.0
2897 Ventspils 2009 23.0 2 0.222222 7 21.0
433 5099 FC Koper 2015 31.0 8 0.800000 2 21.0
5029 FC Koper 2008 10.0 9 0.900000 1 21.0
24197 534 Rudar Prijedor 2012 29.0 10 0.625000 6 21.0

In [93]:
stabilityVsPerf2[stabilityVsPerf2['transfers in']>70]


Out[93]:
league season clubId transfers out points goalsAgainst goalDiff transfers in clubName rank ... GDP 2014 Unemployment Corruption Population Growth % federation marketTier Corruption Rank Bribe % third
1620 IT1 2013 130 26.0 58 46 12 76.0 Parma 6 ... 2147.952 11.3 44.0 60963000.0 0.49 UEFA 1.0 17.0 5.0 True

1 rows × 54 columns


In [89]:
import math
stabilityVsPerf2['third']=stabilityVsPerf2['transfers in']<15 #.apply(lambda x:math.floor(x*10))

stabilityVsPerf2.groupby('third')['invRank'].hist()


Out[89]:
third
False    Axes(0.125,0.125;0.775x0.775)
True     Axes(0.125,0.125;0.775x0.775)
Name: invRank, dtype: object

In [12]:
import math
math.floor(3.5)


Out[12]:
3.0

In [ ]:


In [21]:
stabilityVsPerf.sort_values('transfers in',ascending=False)


Out[21]:
league clubId transfers out points goalsAgainst season goalDiff transfers in clubName rank ... GDP 2013 GDP 2014 Unemployment Corruption Population Growth % federation marketTier Corruption Rank Bribe %
124 BU1 712 39.000000 16 75 1 -55 40.000000 FK Etar 16.000000 ... 54.517 55.837 10.0 41.0 7185000.0 -0.57 UEFA 3.0 23.0 8.0
767 RO1 34767 25.000000 32 47 1 -11 35.000000 Turnu-Severin 16.000000 ... 191.598 199.950 6.7 46.0 19822000.0 -0.41 UEFA 3.0 36.0 17.0
409 IT1 130 27.200000 235 267 5 -38 32.400000 Parma 11.200000 ... 2137.615 2147.952 11.3 44.0 60963000.0 0.49 UEFA 1.0 17.0 5.0
123 BU1 32673 26.000000 18 66 1 -48 31.000000 FC Lyubimets 12.000000 ... 54.517 55.837 10.0 41.0 7185000.0 -0.57 UEFA 3.0 23.0 8.0
1034 ZYP1 26129 7.000000 21 64 1 -37 29.000000 AEK Kouklia 12.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
102 BOS1 17387 15.000000 9 57 1 -40 28.000000 OFK Gradina 16.000000 ... 17.852 17.977 42.8 38.0 3750000.0 -0.64 UEFA 3.0 55.0 28.0
911 TR1 2292 24.000000 77 108 2 -39 27.500000 Elazigspor 14.500000 ... 821.918 806.108 10.5 42.0 78214000.0 1.34 UEFA 2.0 46.0 21.0
771 RO1 40843 17.000000 24 42 1 -14 27.000000 FC Voluntari 12.000000 ... 191.598 199.950 6.7 46.0 19822000.0 -0.41 UEFA 3.0 36.0 17.0
1031 ZYP1 7475 28.000000 41 101 2 -51 27.000000 AE Pafos 13.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
850 SER1 4634 24.333333 121 108 3 -16 26.333333 Vozdovac 8.333333 ... 45.520 43.866 17.3 40.0 7103000.0 -0.41 UEFA 3.0 51.0 26.0
56 AZ1 46710 9.000000 62 30 1 12 26.000000 FK Zira 2.000000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
99 BOS1 33627 11.000000 39 39 1 -10 26.000000 Mladost Doboj 10.000000 ... 17.852 17.977 42.8 38.0 3750000.0 -0.64 UEFA 3.0 55.0 28.0
763 RO1 4688 23.000000 53 118 2 -63 26.000000 Gloria Bistrita 16.000000 ... 191.598 199.950 6.7 46.0 19822000.0 -0.41 UEFA 3.0 36.0 17.0
846 SER1 4633 23.250000 144 143 4 -22 25.750000 Novi Pazar 10.250000 ... 45.520 43.866 17.3 40.0 7103000.0 -0.41 UEFA 3.0 51.0 26.0
867 SL1 23253 22.333333 142 156 3 -28 25.666667 NK Zavrc 6.333333 ... 48.005 49.506 11.7 60.0 2065000.0 0.15 UEFA 3.0 19.0 6.0
919 TR1 2750 18.000000 26 65 1 -28 25.000000 Bucaspor 16.000000 ... 821.918 806.108 10.5 42.0 78214000.0 1.34 UEFA 2.0 46.0 21.0
54 AZ1 33315 14.750000 90 192 4 -98 24.750000 Ravan Baku 9.250000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
752 RO1 6429 23.200000 207 233 5 -42 24.600000 U Cluj 10.600000 ... 191.598 199.950 6.7 46.0 19822000.0 -0.41 UEFA 3.0 36.0 17.0
457 KR1 10314 24.000000 66 80 2 -30 24.500000 Karlovac 1919 10.500000 ... 57.849 57.159 17.9 51.0 4230000.0 -0.31 UEFA 3.0 14.0 4.0
915 TR1 868 22.000000 52 139 2 -65 24.500000 Ankaragücü 15.500000 ... 821.918 806.108 10.5 42.0 78214000.0 1.34 UEFA 2.0 46.0 21.0
755 RO1 15945 21.800000 175 238 5 -72 24.400000 Chiajna 12.800000 ... 191.598 199.950 6.7 46.0 19822000.0 -0.41 UEFA 3.0 36.0 17.0
772 RO1 36593 18.000000 14 69 1 -49 24.000000 Corona Brasov 18.000000 ... 191.598 199.950 6.7 46.0 19822000.0 -0.41 UEFA 3.0 36.0 17.0
398 ISR1 19977 11.000000 26 56 1 -27 24.000000 H. Ashkelon 14.000000 ... NaN NaN 5.4 61.0 NaN NaN UEFA 3.0 25.0 12.0
1035 ZYP1 8554 30.000000 19 47 1 -23 24.000000 APOP Kinyras 14.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
749 RO1 9465 21.200000 235 163 5 51 23.400000 Petr. Ploiesti 8.000000 ... 191.598 199.950 6.7 46.0 19822000.0 -0.41 UEFA 3.0 36.0 17.0
107 BU1 2259 24.500000 264 214 6 18 23.333333 Lok. Plovdiv 6.500000 ... 54.517 55.837 10.0 41.0 7185000.0 -0.57 UEFA 3.0 23.0 8.0
602 MLS1 45604 9.000000 70 95 2 -13 23.000000 Orlando 6.500000 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
339 GR1 441 16.000000 36 54 1 -11 23.000000 Apollon Smyrnis 17.000000 ... 242.306 238.023 24.5 46.0 10769000.0 -0.11 UEFA 2.0 48.0 22.0
126 BU1 760 22.000000 12 66 1 -51 23.000000 Neftochimik 14.000000 ... 54.517 55.837 10.0 41.0 7185000.0 -0.57 UEFA 3.0 23.0 8.0
754 RO1 16650 17.750000 186 134 4 12 22.500000 ASA Tirgu Mures 8.500000 ... 191.598 199.950 6.7 46.0 19822000.0 -0.41 UEFA 3.0 36.0 17.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
27 ALB1 12448 1.000000 34 86 2 -43 1.000000 KF Apolonia 13.000000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
639 NIR1 9026 1.200000 259 198 5 67 1.000000 Glentoran 4.800000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
997 WAL1 3649 1.000000 29 34 1 -3 1.000000 Bangor City FC 7.000000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
996 WAL1 31130 0.000000 32 39 1 -5 1.000000 Newtown 6.000000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
995 WAL1 24530 1.000000 43 20 1 23 1.000000 Neath FC 4.000000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
44 ARM1 10199 1.000000 17 59 1 -40 1.000000 Kilikia Erewan 7.000000 ... NaN NaN 16.6 35.0 3010000.0 -0.03 UEFA 3.0 39.0 18.0
992 WAL1 11915 0.500000 81 51 2 31 1.000000 Llanelli 3.500000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
200 EST1 25408 0.500000 39 138 2 -89 1.000000 Pärnu 8.500000 ... 24.888 25.953 5.2 70.0 1315000.0 0.46 UEFA 3.0 19.0 6.0
313 GEO1 41133 1.000000 39 61 1 -14 1.000000 Saburtalo 9.000000 ... NaN NaN NaN 52.0 3707000.0 -1.23 UEFA 3.0 14.0 4.0
498 LET1 28532 1.500000 52 137 2 -70 1.000000 FB Gulbene-2005 8.500000 ... 30.838 31.970 9.7 55.0 1979000.0 -0.90 UEFA 3.0 42.0 19.0
33 ALB1 27113 1.000000 19 50 1 -20 1.000000 FK Tomori Berat 12.000000 ... 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
987 WAL1 27843 0.333333 106 74 3 29 1.000000 Bala Town 5.000000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
641 NIR1 15244 0.833333 229 374 6 -92 1.000000 Ballymena 7.666667 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
998 WAL1 25232 0.000000 15 50 1 -31 1.000000 Haverfordwest 12.000000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
205 FARO 4313 0.800000 236 138 5 120 0.800000 HB Tórshavn 2.800000 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
988 WAL1 9721 0.500000 102 150 4 -35 0.750000 Port Talbot 8.250000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
986 WAL1 23088 0.750000 142 126 4 43 0.750000 Airbus UK BFC 4.000000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
991 WAL1 22499 0.666667 82 139 3 -26 0.666667 Connah's Quay 7.333333 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
210 FARO 30484 0.666667 58 137 3 -55 0.666667 AB Argir 8.333333 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
990 WAL1 10734 0.500000 99 48 2 72 0.500000 The New Saints 2.000000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
213 FARO 27811 0.500000 38 135 2 -80 0.500000 07 Vestur 9.500000 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
207 FARO 11540 0.500000 180 173 4 65 0.500000 NSÍ Runavík 3.500000 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
993 WAL1 29160 0.500000 55 59 2 3 0.500000 Prestatyn 7.000000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
211 FARO 10538 0.500000 56 87 2 -20 0.500000 B68 Toftir 7.500000 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
212 FARO 10752 0.500000 51 125 2 -57 0.500000 EB/Streymur 7.500000 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
204 FARO 24832 0.833333 287 194 6 122 0.500000 Víkingur Göta 3.666667 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
310 GEO1 751 2.000000 102 97 3 -11 0.333333 WIT Georgia 7.666667 ... NaN NaN NaN 52.0 3707000.0 -1.23 UEFA 3.0 14.0 4.0
989 WAL1 21541 1.000000 102 157 4 -29 0.250000 Aberystwyth 8.750000 ... NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
315 GEO1 22842 2.000000 21 32 1 -11 0.000000 FC Gagra 11.000000 ... NaN NaN NaN 52.0 3707000.0 -1.23 UEFA 3.0 14.0 4.0
576 MAZ1 4644 2.000000 38 34 1 -5 0.000000 FC Shkupi 6.000000 ... 10.774 11.342 24.5 42.0 2071000.0 0.15 UEFA 3.0 36.0 17.0

1038 rows × 55 columns


In [24]:
nonloans[(nonloans.season>2010)].groupby(['toTeamId','toTeamName','season'])['id'].count().sort_values(ascending=False)


Out[24]:
toTeamId  toTeamName       season
515       Unattached       2015      2722
                           2014      2408
                           2012      2151
                           2013      2112
                           2011      1762
123       End of career    2011      1204
                           2013      1143
                           2012      1137
                           2014      1036
75        Unknown          2012       934
                           2013       835
123       End of career    2015       804
75        Unknown          2011       774
                           2014       754
                           2015       753
2113      career break     2012        94
                           2011        83
                           2013        78
130       Parma            2013        76
2113      career break     2014        69
                           2015        49
712       FK Etar          2012        40
3544      Smederevo        2012        38
10314     Karlovac 1919    2011        35
34767     Turnu-Severin    2012        35
4633      Novi Pazar       2012        34
2292      Elazigspor       2012        34
4078      Montreal         2011        33
4959      Otelul Galati    2014        33
33315     Ravan Baku       2015        32
                                     ... 
23167     Gerecja Vas      2014         1
23168     Sladki Vrh       2011         1
23170     Rubio Ñú         2012         1
                           2014         1
23171     Nacional Potosí  2012         1
23107     Jupie Podlavice  2014         1
6626      PAO U20          2014         1
23106     Warri Wolves FC  2015         1
6635      Frohnleiten      2011         1
6640      Club Bruges U19  2013         1
23005     Düsseldorf U17   2014         1
6640      Club Bruges U19  2011         1
23010     Marine FC        2014         1
23023     Sousense         2013         1
6638      CF Badalona      2013         1
23051     Virtus Flaminia  2015         1
23074     Ramsbottom       2012         1
6635      Frohnleiten      2013         1
6632      Kashiwa Reysol   2014         1
23106     Warri Wolves FC  2014         1
23079     Orlici           2013         1
6631      FC Tokyo         2014         1
                           2012         1
23083     Ceahlaul II      2013         1
23085     Cheshunt         2013         1
23088     Airbus UK BFC    2012         1
23093     SG Ehrang/P.     2011         1
6628      Legia II         2014         1
23106     Warri Wolves FC  2012         1
1         Saarbrücken     2012         1
Name: id, dtype: int64

In [34]:



Out[34]:
season
1995              (0.59375, 190, 130, 320)
1996       (0.605485232068, 287, 187, 474)
1997       (0.596989966555, 357, 241, 598)
1998       (0.584827586207, 424, 301, 725)
1999       (0.597371565114, 500, 337, 837)
2000      (0.618099547511, 683, 422, 1105)
2001       (0.63818321786, 829, 470, 1299)
2002     (0.769498607242, 1105, 331, 1436)
2003      (0.79085303186, 1539, 407, 1946)
2004     (0.767398585783, 2062, 625, 2687)
2005     (0.729119638826, 2261, 840, 3101)
2006     (0.697356143079, 2242, 973, 3215)
2007    (0.626192541197, 2166, 1293, 3459)
2008    (0.637260273973, 2326, 1324, 3650)
2009     (0.739482200647, 2742, 966, 3708)
2010    (0.740416773862, 2878, 1009, 3887)
2011     (0.74025974026, 3021, 1060, 4081)
2012      (0.74834605598, 2941, 989, 3930)
2013      (0.76552065298, 3095, 948, 4043)
2014     (0.796167247387, 3199, 819, 4018)
2015     (0.773873000485, 3193, 933, 4126)
dtype: object

In [13]:
nonloans[(nonloans.toTeamId==34767)&(nonloans.season==2012)][['playerName','date']].sort_values('date').date.apply(lambda x:x.split('-')[0]).value_counts()


Out[13]:
2013    21
2012    14
Name: date, dtype: int64

In [62]:
t=nonloans[(nonloans.Nationality!=nonloans.toCountry)&(~nonloans.toCountry.isin(['Italy','Turkey','Germany','United States']))&(nonloans.toTeamId.isin(stabilityVsPerf[stabilityVsPerf['transfers in']>20]['clubId']))&((nonloans.facebook.notnull())|(nonloans.twitter.notnull())|(nonloans.instagram.notnull()))]
t=t.merge(nonloans.groupby(['season','toTeamId'])[['id']].count(),how='left',right_index=True,left_on=['season','toTeamId'],suffixes=('','_y')).rename(columns={'id_y':'transfers'})

players2contact=t[t['transfers']>20][['id','playerName','season','Nationality','toTeamId','toTeamName','toCountry','facebook','twitter','instagram','transfers']]

ew = pd.ExcelWriter('../data/analysis/players2contact.xls', encoding='utf-8')
players2contact.to_excel(ew, merge_cells=False)
ew.save()

players2contact


Out[62]:
id playerName season Nationality toTeamId toTeamName toCountry facebook twitter instagram transfers
57539 195506 Volodya Papikyan 2011 Armenia 256 LKS Lodz Poland http://www.facebook.com/volodya.papikyan/ http://twitter.com/VolodyaPapikyan NaN 21
57544 195505 Aghvan Papikyan 2011 Armenia 256 LKS Lodz Poland http://www.facebook.com/aghvan.papikyan94 http://twitter.com/Agwan94 NaN 21
123853 279468 Ricardo Radina 2015 Croatia 36590 Poli Timisoara Romania NaN NaN http://www.instagram.com/rradina77/ 23
125624 32701 Joël Thomas 2012 France 34767 Turnu-Severin Romania http://www.facebook.com/joel.thomas.925 NaN NaN 35
125937 106229 Alexandre Durimel 2012 France 34767 Turnu-Severin Romania http://www.facebook.com/alexandre.durimel NaN NaN 35
126066 177331 Antonio Asanovic 2012 Croatia 34767 Turnu-Severin Romania http://www.facebook.com/antonio.asanovic NaN NaN 35
126489 111995 Hamza Younes 2011 Tunisia 9465 Petr. Ploiesti Romania http://www.facebook.com/hamza.offishal NaN NaN 28
126493 111995 Hamza Younes 2015 Tunisia 15945 Chiajna Romania http://www.facebook.com/hamza.offishal NaN NaN 25
128832 60125 Igor Kojic 2010 Serbia 3393 D. Katokopias Cyprus NaN http://twitter.com/igorkojic http://instagram.com/igorkojic 21
131121 48662 Vitinha 2011 Portugal 15945 Chiajna Romania http://www.facebook.com/vitinha.vitortiago NaN NaN 27
189447 19081 Lukasz Szukala 2010 Poland 4688 Gloria Bistrita Romania https://www.facebook.com/szukala?fref=pb&hc_lo... NaN NaN 21
189449 19081 Lukasz Szukala 2012 Poland 9465 Petr. Ploiesti Romania https://www.facebook.com/szukala?fref=pb&hc_lo... NaN NaN 26
190536 9800 Artem Milevsky 2015 Ukraine 15945 Chiajna Romania NaN NaN https://instagram.com/timi1010 25
243303 159773 Pablo Ceppelini 2014 Uruguay 6429 U Cluj Romania NaN https://twitter.com/Pablo_Ceppelini https://www.instagram.com/pablo_ceppelini/ 27
243619 75611 Nicolás Gorobsov 2014 Argentina 16650 ASA Tirgu Mures Romania https://www.facebook.com/nicolas.gorobsov https://twitter.com/NicolasGorobsov NaN 21
277532 131942 Iván González 2014 Spain 16650 ASA Tirgu Mures Romania NaN https://twitter.com/IvanGonzalezL5 NaN 21
294359 13783 Lee Cook 2013 England 441 Apollon Smyrnis Greece NaN https://twitter.com/cookie17lee NaN 23
297349 7373 Albert Riera 2015 Spain 23253 NK Zavrc Slovenia NaN https://twitter.com/RIERA11 NaN 31

In [51]:
t.merge(nonloans.groupby(['season','toTeamId'])[['id']].count(),how='left',right_index=True,left_on=['season','toTeamId'])


Out[51]:
id_x playerName date season fromCountry fromLeague fromTeamId fromTeamName toCountry toLeague ... website feeValue isLoan age ageFloat period mvDelta duration durationWithLoans id_y
47066 2937 Helge Payer 2012-08-24 2012 Austria A1 170 Rapid Vienna Greece Other Greece ... http://www.helgepayer.com/ 0.0 False 33.0 32.39765 (2010, 2015] 0.0 4041.0 4041.0 13
57539 195506 Volodya Papikyan 2011-07-01 2011 Poland Other Poland 15523 LKS U19 Poland PL1 ... NaN NaN False 18.0 17.99079 (2010, 2015] NaN NaN NaN 21
57544 195505 Aghvan Papikyan 2011-07-01 2011 Poland Other Poland 15523 LKS U19 Poland PL1 ... NaN NaN False 17.0 16.89562 (2010, 2015] NaN NaN NaN 21
123853 279468 Ricardo Radina 2015-10-13 2015 NaN NaN 515 Unattached Romania RO1 ... NaN NaN False 19.0 18.59586 (2010, 2015] 0.0 104.0 104.0 23
124804 214781 Esmir Ahmetovic 2014-01-29 2013 NaN NaN 75 Unknown Romania RO1 ... NaN NaN False 22.0 21.95801 (2010, 2015] 0.0 181.0 181.0 18
125008 107849 Danijel Morariju 2014-01-29 2013 Albania ALB1 13645 KS Lushnja Romania RO1 ... NaN 0.0 False 22.0 22.00182 (2010, 2015] 0.0 152.0 152.0 18
125181 180447 Wilson Kneeshaw 2014-02-28 2013 England GB21 9256 Boro U21 Romania RO1 ... http://www.wilsonkneeshaw.com 0.0 False 19.0 18.62051 (2010, 2015] 0.0 607.0 607.0 18
125535 99342 Edon Hasani 2014-01-29 2013 Romania RO1 8687 C. Piatra Neamt Romania RO1 ... NaN 0.0 False 21.0 20.98058 (2010, 2015] -150000.0 198.0 198.0 18
125622 32701 Joël Thomas 2011-08-01 2011 Greece Other Greece 553 Ionikos Nikea Greece Other Greece ... NaN 0.0 False 24.0 23.50767 (2010, 2015] -125000.0 212.0 212.0 9
125624 32701 Joël Thomas 2012-07-01 2012 NaN NaN 515 Unattached Romania RO1 ... NaN NaN False 25.0 24.50701 (2010, 2015] 0.0 182.0 182.0 35
125937 106229 Alexandre Durimel 2012-08-01 2012 France Other France 1416 SC Amiens Romania RO1 ... NaN 0.0 False 22.0 21.79648 (2010, 2015] 0.0 1127.0 1127.0 35
126066 177331 Antonio Asanovic 2013-01-11 2012 Croatia KR1 447 Hajduk Split Romania RO1 ... NaN 0.0 False 21.0 20.39741 (2010, 2015] 0.0 NaN 529.0 35
126489 111995 Hamza Younes 2012-01-01 2011 Tunisia TUN1 250 ES Sahel Romania RO1 ... NaN 150000.0 False 25.0 24.71235 (2010, 2015] 0.0 123.0 123.0 28
126493 111995 Hamza Younes 2016-02-16 2015 Iran IRN1 12935 Tractor Sazi Romania RO1 ... NaN 0.0 False 29.0 28.71243 (2010, 2015] -500000.0 213.0 213.0 25
128311 105584 Souleymane Keita 2009-08-01 2009 Romania Other Romania 8818 FC Botosani Romania RO1 ... NaN 5000.0 False 22.0 21.16128 (2005, 2010] 0.0 396.0 396.0 11
128313 105584 Souleymane Keita 2013-07-01 2013 Romania Other Romania 33966 CSMS Iasi Romania RO1 ... NaN 0.0 False 26.0 25.16137 (2010, 2015] 75000.0 365.0 365.0 18
128832 60125 Igor Kojic 2011-01-01 2010 Romania RO1 312 Dinamo Bukarest Cyprus ZYP1 ... http://www.igorkojic.com 0.0 False 23.0 22.42620 (2005, 2010] 75000.0 730.0 730.0 21
131121 48662 Vitinha 2011-07-01 2011 Romania Other Romania 12682 CS Otopeni Romania RO1 ... NaN NaN False 25.0 24.88757 (2010, 2015] 0.0 181.0 181.0 27
163034 59755 Macoumba Kandji 2013-01-26 2012 United States MLS1 9168 Houston Greece Other Greece ... NaN 0.0 False 27.0 26.41533 (2010, 2015] 0.0 360.0 360.0 13
189447 19081 Lukasz Szukala 2010-08-01 2010 Germany L2 8 Alem. Aachen Romania RO1 ... NaN 0.0 False 26.0 25.60217 (2005, 2010] 100000.0 761.0 761.0 21
189448 19081 Lukasz Szukala 2011-07-01 2011 Romania Other Romania 4688 Gloria Bistrita Romania RO1 ... NaN 300000.0 False 27.0 26.60150 (2010, 2015] 150000.0 334.0 334.0 16
189449 19081 Lukasz Szukala 2012-07-01 2012 Romania RO1 6429 U Cluj Romania RO1 ... NaN 300000.0 False 28.0 27.60084 (2010, 2015] 450000.0 366.0 366.0 26
190536 9800 Artem Milevsky 2016-02-05 2015 NaN NaN 515 Unattached Romania RO1 ... NaN NaN False 30.0 29.96913 (2010, 2015] 0.0 91.0 91.0 25
243303 159773 Pablo Ceppelini 2014-09-08 2014 Italy IT1 1390 Cagliari Calcio Romania RO1 ... NaN 0.0 False 23.0 22.30847 (2010, 2015] -200000.0 1316.0 371.0 27
243619 75611 Nicolás Gorobsov 2014-07-24 2014 Italy IT1 416 Torino Romania RO1 ... NaN NaN False 25.0 24.10180 (2010, 2015] 50000.0 1849.0 365.0 21
277532 131942 Iván González 2015-02-03 2014 NaN NaN 515 Unattached Romania RO1 ... NaN NaN False 26.0 25.87870 (2010, 2015] 0.0 125.0 125.0 21
294359 13783 Lee Cook 2014-01-02 2013 NaN NaN 515 Unattached Greece GR1 ... NaN NaN False 31.0 30.41541 (2010, 2015] 0.0 185.0 185.0 23
296925 41990 Gabriel Zakuani 2014-01-02 2013 England GB3 1072 Peterborough Greece GR1 ... NaN 0.0 False 27.0 26.59055 (2010, 2015] 100000.0 1949.0 1949.0 18
297349 7373 Albert Riera 2015-09-15 2015 Spain ES2 237 RCD Mallorca Slovenia SL1 ... NaN 0.0 False 33.0 32.71525 (2010, 2015] -1500000.0 194.0 194.0 31

29 rows × 63 columns


In [160]:
nonloans[(nonloans.toTeamId==34767)&(nonloans.facebook.notnull())]['id'] #.groupby('season').count()['id']


Out[160]:
125624     32701
125937    106229
126066    177331
Name: id, dtype: int64

In [139]:
stabilityVsPerf['goalDiffPerSeason']=stabilityVsPerf.goalDiff/stabilityVsPerf.season
print stabilityVsPerf[(stabilityVsPerf['transfers in']>15)].goalDiffPerSeason.apply(lambda x:x>0).value_counts()
print stabilityVsPerf[(stabilityVsPerf['transfers in']>0)].season.mean()

stabilityVsPerf[(stabilityVsPerf['transfers in']>15)].groupby('league').count()['clubId'].sort_values(ascending=False).drop('MLS1').plot.pie() #.sum()


False    163
True      42
Name: goalDiffPerSeason, dtype: int64
3.82625482625
Out[139]:
<matplotlib.axes._subplots.AxesSubplot at 0x10a406c50>

In [2]:
stabilityVsPerf[(stabilityVsPerf['goalDiff']>-10000)&(stabilityVsPerf.season>5)]['transfers in'].mean()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-1f72abb3cc4a> in <module>()
----> 1 stabilityVsPerf[(stabilityVsPerf['goalDiff']>-10000)&(stabilityVsPerf.season>5)]['transfers in'].mean()

NameError: name 'stabilityVsPerf' is not defined

In [22]:
580 /831.


Out[22]:
0.6979542719614922

In [120]:
stabilityVsPerf[stabilityVsPerf.Country.isnull()]


Out[120]:
league clubId transfers out points goalsAgainst season goalDiff transfers in clubName rank ... GDP 2013 GDP 2014 Unemployment Corruption Population Growth % federation marketTier Corruption Rank Bribe %

0 rows × 55 columns


In [118]:
countryLeagueMap=nonloans[['fromCountry','fromLeague']].drop_duplicates().rename(columns={'fromLeague':'league','fromCountry':'Country'})
stabilityVsPerf.merge(countryLeagueMap,how='left',left_on='league',right_on='league').merge(countryInfo,how='left',left_on='Country',right_index=True)


Out[118]:
league clubId transfers out points goalsAgainst season goalDiff transfers in clubName rank ... GDP 2013 GDP 2014 Unemployment Corruption Population Growth % federation marketTier Corruption Rank Bribe %
0 A1 409 11.166667 435 210 6 274 12.500000 RB Salzburg 1.333333 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
1 A1 170 8.500000 366 231 6 127 8.500000 Rapid Vienna 2.666667 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
2 A1 14 10.666667 352 255 6 114 11.333333 Austria Vienna 3.666667 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
3 A1 122 11.333333 319 266 6 48 11.666667 Sturm Graz 4.000000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
4 A1 266 10.500000 281 304 6 -9 10.833333 SV Ried 5.833333 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
5 A1 503 9.600000 216 299 5 -65 11.600000 Admira Wacker 6.800000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
6 A1 17444 12.200000 187 326 5 -144 12.400000 Wiener Neustadt 8.200000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
7 A1 4441 8.500000 183 205 4 -25 9.250000 Wolfsberger AC 5.750000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
8 A1 2444 7.500000 160 232 4 -70 8.500000 FC Wacker 7.750000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
9 A1 856 4.750000 143 236 4 -90 7.000000 SV Mattersburg 9.000000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
10 A1 10131 10.333333 126 192 3 -36 13.000000 SV Grödig 7.000000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
11 A1 3551 2.500000 99 98 2 -9 8.500000 SCR Altach 5.500000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
12 A1 2394 17.500000 61 125 2 -62 16.500000 SV Kapfenberg 9.000000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
13 A1 413 19.000000 19 75 1 -53 20.000000 LASK 10.000000 ... 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
14 AZ1 10625 10.000000 310 100 5 147 9.000000 Qarabag Agdam 2.000000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
15 AZ1 8956 14.600000 278 108 5 94 14.200000 Inter Baku 2.400000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
16 AZ1 8031 11.600000 251 160 5 59 9.800000 Neftchi Baku 3.200000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
17 AZ1 22010 15.200000 247 149 5 44 13.800000 FK Gabala 4.000000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
18 AZ1 13326 15.600000 175 191 5 -30 16.400000 AZAL 7.000000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
19 AZ1 8841 16.200000 171 192 5 -30 13.800000 Xäzär Länkäran 6.800000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
20 AZ1 13328 8.750000 143 116 4 5 11.250000 Simurq 6.500000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
21 AZ1 10693 15.750000 142 149 4 -24 12.250000 FC Baku 6.250000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
22 AZ1 36999 11.600000 132 232 5 -98 15.200000 Sumgayit 9.400000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
23 AZ1 33315 14.750000 90 192 4 -98 24.750000 Ravan Baku 9.250000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
24 AZ1 7090 11.666667 88 123 3 -37 14.333333 Kapaz Ganja 8.666667 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
25 AZ1 46710 9.000000 62 30 1 12 26.000000 FK Zira 2.000000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
26 AZ1 9526 15.000000 34 68 2 -31 16.500000 Turan 10.500000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
27 AZ1 44360 29.000000 4 20 1 -13 19.000000 Araz-Naxcivan 10.000000 ... NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
28 BE1 58 10.666667 368 163 6 188 11.000000 RSC Anderlecht 2.000000 ... 524.970 534.672 7.8 77.0 11259000.0 0.52 UEFA 2.0 14.0 4.0
29 BE1 2282 12.000000 356 196 6 168 13.166667 Club Brugge 2.333333 ... 524.970 534.672 7.8 77.0 11259000.0 0.52 UEFA 2.0 14.0 4.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
801 UNG1 5378 15.333333 96 151 3 -56 19.333333 Vasas FC 12.000000 ... 133.424 137.104 6.2 51.0 9835000.0 -0.28 UEFA 3.0 25.0 12.0
802 UNG1 3552 13.333333 95 143 3 -53 13.000000 BFC Siófok 12.666667 ... 133.424 137.104 6.2 51.0 9835000.0 -0.28 UEFA 3.0 25.0 12.0
803 UNG1 1391 10.000000 61 112 2 -36 11.500000 Zalaegerszeg 10.000000 ... 133.424 137.104 6.2 51.0 9835000.0 -0.28 UEFA 3.0 25.0 12.0
804 UNG1 6058 11.000000 30 49 1 -16 18.000000 Nyíregyháza 12.000000 ... 133.424 137.104 6.2 51.0 9835000.0 -0.28 UEFA 3.0 25.0 12.0
805 UNG1 6049 4.000000 27 55 1 -30 19.000000 Békéscsaba 12.000000 ... 133.424 137.104 6.2 51.0 9835000.0 -0.28 UEFA 3.0 25.0 12.0
806 UNG1 24032 9.000000 24 52 1 -25 12.000000 Mezőkövesd 15.000000 ... 133.424 137.104 6.2 51.0 9835000.0 -0.28 UEFA 3.0 25.0 12.0
807 UNG1 27165 10.000000 23 49 1 -23 14.000000 Dunaújváros 15.000000 ... 133.424 137.104 6.2 51.0 9835000.0 -0.28 UEFA 3.0 25.0 12.0
808 UNG1 5399 13.000000 21 56 1 -30 14.000000 Szolnok 16.000000 ... 133.424 137.104 6.2 51.0 9835000.0 -0.28 UEFA 3.0 25.0 12.0
809 UNG1 27397 13.000000 15 67 1 -42 22.000000 Egri FC 16.000000 ... 133.424 137.104 6.2 51.0 9835000.0 -0.28 UEFA 3.0 25.0 12.0
810 ZYP1 2784 11.333333 351 91 6 221 11.166667 APOEL Nicosia 1.666667 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
811 ZYP1 829 14.000000 295 122 6 136 13.000000 Omonia Nikosia 3.333333 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
812 ZYP1 3899 15.166667 285 144 6 115 13.666667 Anor. Famagusta 3.833333 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
813 ZYP1 2156 15.333333 276 140 6 104 14.333333 AEK Larnaca 4.333333 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
814 ZYP1 429 15.000000 268 169 6 72 14.166667 Apol. Limassol 4.500000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
815 ZYP1 786 18.166667 267 143 6 67 15.500000 AEL Limassol 5.166667 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
816 ZYP1 4590 17.666667 153 208 6 -62 17.000000 Ethnikos 9.833333 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
817 ZYP1 18945 19.400000 149 188 5 -58 19.200000 Nea Salamis 7.800000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
818 ZYP1 24326 23.000000 148 184 5 -46 21.000000 Ermis Aradippou 9.200000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
819 ZYP1 840 18.600000 135 176 5 -53 16.600000 En. Paralimni 9.800000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
820 ZYP1 3393 22.400000 122 219 5 -90 20.600000 D. Katokopias 10.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
821 ZYP1 1402 17.000000 93 119 3 -13 17.333333 Olympiakos N. 8.666667 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
822 ZYP1 8701 18.750000 90 204 4 -95 17.000000 Alki Larnaca 10.500000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
823 ZYP1 10586 13.000000 78 106 3 -21 16.333333 Aris Limassol 10.666667 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
824 ZYP1 7475 28.000000 41 101 2 -51 27.000000 AE Pafos 13.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
825 ZYP1 10816 13.666667 30 165 3 -112 17.000000 Agia Napa 12.333333 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
826 ZYP1 45457 13.000000 27 47 1 -12 15.000000 Pafos FC 10.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
827 ZYP1 26129 7.000000 21 64 1 -37 29.000000 AEK Kouklia 12.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
828 ZYP1 8554 30.000000 19 47 1 -23 24.000000 APOP Kinyras 14.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
829 ZYP1 30606 5.000000 16 26 1 -13 12.000000 Othellos Athienou 11.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
830 ZYP1 6043 9.000000 11 45 1 -29 20.000000 Anagennisi Dery 13.000000 ... 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0

831 rows × 55 columns


In [72]:
stabilityVsPerf[(stabilityVsPerf['clubName']!=stabilityVsPerf['clubName_uefa'])&(stabilityVsPerf['clubName_uefa'].notnull())]


Out[72]:
league clubId transfers out points goalsAgainst season goalDiff transfers in clubName rank ... scaleRank duration durationWithLoans rank_uefa clubName_uefa coeff12 coeff13 coeff14 coeff15 points_uefa
247 GR1 128 20.166667 230 223 6 -20 19.833333 Skoda Xanthi 10.666667 ... 0.592593 730.115702 567.033113 205.0 AO Xanthi 880.0 2220.0 1240.0 960.0 5300.0
369 L1 27 6.333333 486 138 6 372 6.000000 Bayern Munich 1.500000 ... 0.083333 1390.184211 1004.750000 2.0 Bayern Munich 36585.0 29942.0 31171.0 32285.0 129983.0
619 RU1 2703 18.000000 19 53 1 -27 16.000000 Alania 16.000000 ... 1.000000 708.470588 595.578947 157.0 Spartak 1950.0 2083.0 1933.0 1700.0 7666.0
690 SL1 710 16.666667 275 285 6 -41 15.333333 NK Celje 6.000000 ... 0.600000 539.793478 465.450820 312.0 NK Celje 900.0 775.0 800.0 450.0 2925.0
789 UNG1 6055 10.200000 268 175 5 77 9.200000 ETO FC Győr 4.600000 ... 0.287500 1092.285714 739.585714 306.0 ETO FC Győr 600.0 1175.0 925.0 325.0 3025.0
796 UNG1 12423 13.000000 199 226 5 -19 13.000000 Kecskeméti TE 8.800000 ... 0.550000 636.746032 506.000000 387.0 Kecskeméti LC 600.0 175.0 425.0 325.0 1525.0

6 rows × 22 columns


In [43]:
stabilityVsPerf.join(nonloans[nonloans['season'].between(2010,2015)].rename(columns={'fromLeague':'league','fromTeamId':'clubId'}).groupby(['league','clubId'])[['duration','durationWithLoans']].mean())


Out[43]:
transfers out points goalsAgainst season goalDiff transfers in clubName rank goalsFor invRank scaleRank duration durationWithLoans
league clubId
A1 409 11.166667 435 210 6 274 12.500000 RB Salzburg 1.333333 484 8.666667 0.133333 935.149254 798.119403
170 8.500000 366 231 6 127 8.500000 Rapid Vienna 2.666667 358 7.333333 0.266667 1312.431373 1066.019608
14 10.666667 352 255 6 114 11.333333 Austria Vienna 3.666667 369 6.333333 0.366667 936.531250 870.078125
122 11.333333 319 266 6 48 11.666667 Sturm Graz 4.000000 314 6.000000 0.400000 815.367647 750.352941
266 10.500000 281 304 6 -9 10.833333 SV Ried 5.833333 295 4.166667 0.583333 875.507937 773.444444
503 9.600000 216 299 5 -65 11.600000 Admira Wacker 6.800000 234 3.200000 0.680000 832.750000 797.791667
17444 12.200000 187 326 5 -144 12.400000 Wiener Neustadt 8.200000 182 1.800000 0.820000 738.688525 687.196721
4441 8.500000 183 205 4 -25 9.250000 Wolfsberger AC 5.750000 180 4.250000 0.575000 818.676471 790.764706
2444 7.500000 160 232 4 -70 8.500000 FC Wacker 7.750000 162 2.250000 0.775000 1069.000000 1000.533333
856 4.750000 143 236 4 -90 7.000000 SV Mattersburg 9.000000 146 1.000000 0.900000 1413.684211 1355.684211
10131 10.333333 126 192 3 -36 13.000000 SV Grödig 7.000000 156 3.000000 0.700000 708.935484 708.935484
3551 2.500000 99 98 2 -9 8.500000 SCR Altach 5.500000 89 4.500000 0.550000 327.200000 284.000000
2394 17.500000 61 125 2 -62 16.500000 SV Kapfenberg 9.000000 63 1.000000 0.900000 692.800000 666.742857
413 19.000000 19 75 1 -53 20.000000 LASK 10.000000 22 0.000000 1.000000 679.210526 629.947368
AZ1 10625 10.000000 310 100 5 147 9.000000 Qarabag Agdam 2.000000 247 10.000000 0.166667 825.523810 725.755556
8956 14.600000 278 108 5 94 14.200000 Inter Baku 2.400000 202 9.600000 0.200000 702.963415 656.662651
8031 11.600000 251 160 5 59 9.800000 Neftchi Baku 3.200000 219 8.800000 0.266667 786.986111 717.662162
22010 15.200000 247 149 5 44 13.800000 FK Gabala 4.000000 193 8.000000 0.333333 611.558442 589.519481
13326 15.600000 175 191 5 -30 16.400000 AZAL 7.000000 161 5.000000 0.583333 595.035714 572.928571
8841 16.200000 171 192 5 -30 13.800000 Xäzär Länkäran 6.800000 162 5.200000 0.566667 594.736264 534.815217
13328 8.750000 143 116 4 5 11.250000 Simurq 6.500000 121 5.500000 0.541667 491.500000 491.500000
10693 15.750000 142 149 4 -24 12.250000 FC Baku 6.250000 125 5.750000 0.520833 814.048387 785.666667
36999 11.600000 132 232 5 -98 15.200000 Sumgayit 9.400000 134 2.600000 0.783333 392.692308 392.692308
33315 14.750000 90 192 4 -98 24.750000 Ravan Baku 9.250000 94 2.750000 0.770833 306.075472 303.759259
7090 11.666667 88 123 3 -37 14.333333 Kapaz Ganja 8.666667 86 3.333333 0.722222 395.000000 395.000000
46710 9.000000 62 30 1 12 26.000000 FK Zira 2.000000 42 10.000000 0.166667 238.111111 238.111111
9526 15.000000 34 68 2 -31 16.500000 Turan 10.500000 37 1.500000 0.875000 334.080000 334.080000
44360 29.000000 4 20 1 -13 19.000000 Araz-Naxcivan 10.000000 7 2.000000 0.833333 236.192308 236.192308
BE1 58 10.666667 368 163 6 188 11.000000 RSC Anderlecht 2.000000 351 14.000000 0.125000 1143.065574 709.492063
2282 12.000000 356 196 6 168 13.166667 Club Brugge 2.333333 364 13.666667 0.145833 1075.375000 832.819444
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
UNG1 5378 15.333333 96 151 3 -56 19.333333 Vasas FC 12.000000 95 4.000000 0.750000 563.227273 433.522727
3552 13.333333 95 143 3 -53 13.000000 BFC Siófok 12.666667 90 3.333333 0.791667 554.282051 463.650000
1391 10.000000 61 112 2 -36 11.500000 Zalaegerszeg 10.000000 76 6.000000 0.625000 551.263158 530.052632
6058 11.000000 30 49 1 -16 18.000000 Nyíregyháza 12.000000 33 4.000000 0.750000 377.636364 377.636364
6049 4.000000 27 55 1 -30 19.000000 Békéscsaba 12.000000 25 4.000000 0.750000 421.750000 421.750000
24032 9.000000 24 52 1 -25 12.000000 Mezőkövesd 15.000000 27 1.000000 0.937500 826.666667 622.555556
27165 10.000000 23 49 1 -23 14.000000 Dunaújváros 15.000000 26 1.000000 0.937500 385.000000 385.000000
5399 13.000000 21 56 1 -30 14.000000 Szolnok 16.000000 26 0.000000 1.000000 423.923077 380.384615
27397 13.000000 15 67 1 -42 22.000000 Egri FC 16.000000 25 0.000000 1.000000 357.538462 357.538462
ZYP1 2784 11.333333 351 91 6 221 11.166667 APOEL Nicosia 1.666667 312 12.333333 0.119048 1084.507692 903.507463
829 14.000000 295 122 6 136 13.000000 Omonia Nikosia 3.333333 258 10.666667 0.238095 713.098765 645.365854
3899 15.166667 285 144 6 115 13.666667 Anor. Famagusta 3.833333 259 10.166667 0.273810 677.418605 601.678161
2156 15.333333 276 140 6 104 14.333333 AEK Larnaca 4.333333 244 9.666667 0.309524 485.696203 441.333333
429 15.000000 268 169 6 72 14.166667 Apol. Limassol 4.500000 241 9.500000 0.321429 649.232558 606.681818
786 18.166667 267 143 6 67 15.500000 AEL Limassol 5.166667 210 8.833333 0.369048 583.848485 554.872549
4590 17.666667 153 208 6 -62 17.000000 Ethnikos 9.833333 146 4.166667 0.702381 523.584158 529.166667
18945 19.400000 149 188 5 -58 19.200000 Nea Salamis 7.800000 130 6.200000 0.557143 432.406593 438.376344
24326 23.000000 148 184 5 -46 21.000000 Ermis Aradippou 9.200000 138 4.800000 0.657143 390.752294 383.724771
840 18.600000 135 176 5 -53 16.600000 En. Paralimni 9.800000 123 4.200000 0.700000 615.151163 615.151163
3393 22.400000 122 219 5 -90 20.600000 D. Katokopias 10.000000 129 4.000000 0.714286 441.297030 436.475728
1402 17.000000 93 119 3 -13 17.333333 Olympiakos N. 8.666667 106 5.333333 0.619048 327.695652 328.000000
8701 18.750000 90 204 4 -95 17.000000 Alki Larnaca 10.500000 109 3.500000 0.750000 431.157143 412.885714
10586 13.000000 78 106 3 -21 16.333333 Aris Limassol 10.666667 85 3.333333 0.761905 538.657895 529.052632
7475 28.000000 41 101 2 -51 27.000000 AE Pafos 13.000000 50 1.000000 0.928571 436.214286 436.214286
10816 13.666667 30 165 3 -112 17.000000 Agia Napa 12.333333 53 1.666667 0.880952 414.702703 414.702703
45457 13.000000 27 47 1 -12 15.000000 Pafos FC 10.000000 35 4.000000 0.714286 337.692308 335.307692
26129 7.000000 21 64 1 -37 29.000000 AEK Kouklia 12.000000 27 2.000000 0.857143 348.714286 348.714286
8554 30.000000 19 47 1 -23 24.000000 APOP Kinyras 14.000000 24 0.000000 1.000000 471.172414 458.586207
30606 5.000000 16 26 1 -13 12.000000 Othellos Athienou 11.000000 13 3.000000 0.785714 347.200000 347.200000
6043 9.000000 11 45 1 -29 20.000000 Anagennisi Dery 13.000000 16 1.000000 0.928571 449.333333 449.333333

831 rows × 13 columns


In [20]:
transfers[transfers.toTeamId.isin([131,27,418])].groupby(['toTeamId','season'])['id'].count().unstack()[range(2011,2016)].T #.mean() #.plot.line()


Out[20]:
toTeamId 27.0 131.0 418.0
season
2011.0 6.0 4.0 5.0
2012.0 10.0 7.0 4.0
2013.0 6.0 6.0 8.0
2014.0 8.0 9.0 6.0
2015.0 7.0 6.0 7.0

In [8]:
transfers[transfers.toLeague.isin(['L1','ES1'])&(transfers.toTeamName.str.contains('al Mad')|transfers.toTeamName.str.contains('Barcelona')|transfers.toTeamName.str.contains('Bayern'))][['toTeamId','toTeamName']].drop_duplicates()


Out[8]:
toTeamId toTeamName
20899 131.0 FC Barcelona
43869 27.0 Bayern Munich
54405 418.0 Real Madrid

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
import dateutil


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

nonloans.contractUntil=nonloans.contractUntil.apply(lambda d: dateutil.parser.parse(d) if type(d) == type('') else np.nan)
nonloans.contractThereUntil=nonloans.contractThereUntil.apply(lambda d: dateutil.parser.parse(d) if type(d) == type('') else np.nan)

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','IR1']

countryInfo=pd.read_excel('../data/reference/countries.xls').set_index('country')
countryInfo.marketTier=np.where(countryInfo.marketTier==4,3,countryInfo.marketTier)

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
top50clubids=transfers.groupby('toTeamId')[['feeValue']].sum().merge(DataFrame({'teamName':teamIdMap}), left_index=True,right_index=True,how='left').sort_values('feeValue',ascending=False).iloc[:50].index
top100clubids=transfers.groupby('toTeamId')[['feeValue']].sum().merge(DataFrame({'teamName':teamIdMap}), left_index=True,right_index=True,how='left').sort_values('feeValue',ascending=False).iloc[:100].index

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

country_coeff=pd.read_csv('../data/reference/country_coefficient2.csv').reset_index(drop=True).set_index('Country').rename(index={
        'Bosnia and Herzegovina': 'Bosnia-Herzegovina',
        'Republic of Ireland': 'Ireland',
        'FYR Macedonia': 'Macedonia',
        'Faroe Islands':'Faroe Islands'
    })

natteam_coeff=pd.read_table('../data/reference/national_team_coefficient.csv').reset_index(drop=True).drop('Rank',axis=1)
natteam_coeff['Country']=natteam_coeff['Country'].str.strip()
natteam_coeff.Coefficient=natteam_coeff.Coefficient.apply(lambda s: int(s.replace(',','')))
natteam_coeff=natteam_coeff.rename(columns={'Coefficient':'National team coeff'}).set_index('Country')

club_coeff=pd.read_csv('../data/reference/club_coefficients.csv')[['rank','clubId','clubName','coeff12','coeff13','coeff14','coeff15','points']]

gdp=pd.read_table('../data/reference/country_gdp.csv').reset_index(drop=True).drop('2014 Rank',axis=1).rename(columns={'Country ':'Country'})
gdp.Country=gdp.Country.str.strip()
gdp=gdp.set_index('Country')
gdp.columns=['GDP '+c for c in gdp.columns.str.strip()]
for column in gdp.columns:
    gdp[column]=gdp[column].apply(lambda s: float(str(s).replace(',','')))
    
unemployed=pd.read_table('../data/reference/country_unemployment.csv').drop(['Date','Employment rate'],axis=1)
unemployed.columns=['Country','Unemployment']
unemployed['Country']=unemployed['Country'].str.split(' ').apply(lambda arr: ' '.join(arr[:len(arr)/2]))
unemployed=unemployed.set_index('Country').rename(index={'United Kingdom':'England'})

corruption=pd.read_table('../data/reference/country_corruption.csv').drop(['Rank'],axis=1)
corruption.Country=corruption.Country.str.strip()
corruption=corruption.set_index('Country')
corruption=corruption[corruption.columns[:1]].rename(columns={'2015 score':'Corruption'}).rename(index={'United Kingdom':'England'})

population=pd.read_table('../data/reference/country_population.csv').drop(['Rank'],axis=1)
population.columns=population.columns.str.strip()
population.Country=population.Country.str.split('[',expand=True)[0].str.strip()
population['Population']=population['Population'].apply(lambda s: float(str(s).replace(',','')))
population=population[['Country','Population','Growth %']].set_index('Country').rename(index={'United Kingdom':'England'})

barometer=pd.read_table('../data/reference/country_corruption_barometer.csv').reset_index(drop=True)
barometer.columns=['Corruption Rank','Country','Bribe %']
barometer.Country=barometer.Country.str.strip()
barometer=barometer.set_index('Country').rename(index={'United Kingdom':'England'})

countryInfo=natteam_coeff.join(country_coeff).join(gdp).join(unemployed).join(corruption).join(population).join(countryInfo).join(barometer)


/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 [133]:
j=nonloans[nonloans.contractUntil.notnull()][['id','currentClubId','contractUntil']].drop_duplicates('id').merge(leagueTables[['clubId','league']],how='left',left_on='currentClubId',right_on='clubId').drop_duplicates('id')
today=dateutil.parser.parse('2016-09-01')

j['contractLeft']=((j.contractUntil - today) / np.timedelta64(1, 'D')).astype(int)/366
g=j[j.contractLeft>0].groupby('league')['contractLeft'].describe().unstack()
g[g['count']>200].sort_values('50%')


Out[133]:
count mean std min 25% 50% 75% max
league
FI1 358.0 0.592446 0.509876 0.327869 0.330601 0.330601 0.330601 3.322404
IR1 315.0 0.352745 0.147181 0.327869 0.330601 0.330601 0.330601 1.327869
MLS1 210.0 0.645576 0.847235 0.163934 0.330601 0.330601 0.330601 4.322404
A1 211.0 1.414083 0.811564 0.743169 0.825137 0.825137 1.822404 4.816940
SC1 250.0 1.356612 0.762527 0.330601 0.743169 0.825137 1.822404 4.816940
PL1 298.0 1.479829 0.839870 0.330601 0.825137 0.825137 1.822404 4.322404
GR1 339.0 1.460685 0.755407 0.330601 0.825137 0.825137 1.822404 3.819672
NL1 361.0 1.521464 0.895660 0.825137 0.825137 0.825137 1.822404 3.819672
DK1 267.0 1.571028 0.911629 0.330601 0.825137 1.327869 1.822404 4.322404
NO1 422.0 1.298157 0.874272 0.245902 0.330601 1.327869 2.325137 4.322404
SE1 379.0 1.303913 0.902795 0.245902 0.330601 1.327869 2.325137 4.322404
RU1 247.0 1.816885 0.957719 0.330601 0.825137 1.822404 2.819672 3.819672
PO1 292.0 1.928653 1.189791 0.825137 0.825137 1.822404 2.819672 5.814208
IT1 475.0 2.084211 1.046837 0.330601 0.825137 1.822404 2.819672 4.816940
GB1 692.0 2.025996 1.114724 0.825137 0.825137 1.822404 2.819672 5.814208
FR1 480.0 1.746784 0.941441 0.330601 0.825137 1.822404 2.819672 3.819672
ES1 417.0 2.039300 1.170775 0.330601 0.825137 1.822404 2.819672 4.816940
C1 218.0 1.566388 0.880668 0.330601 0.825137 1.822404 1.822404 4.816940
BE1 363.0 1.725097 0.934077 0.825137 0.825137 1.822404 2.073770 4.816940
L1 597.0 1.714003 0.963583 0.825137 0.825137 1.822404 1.822404 4.816940
TR1 442.0 1.551739 0.821977 0.825137 0.825137 1.822404 1.822404 3.819672

In [39]:
LeagueClubSizes=pd.read_csv('../data/merged/LeagueClubSizes.csv').rename()
LeagueClubSizes


Out[39]:
clubId clubName size league
0 119 maccabi-tel-aviv 29 ISR1
1 1064 maccabi-haifa 34 ISR1
2 1017 hapoel-tel-aviv 35 ISR1
3 3793 beitar-jerusalem 31 ISR1
4 2976 hapoel-beer-sheva 25 ISR1
5 5223 maccabi-netanya 45 ISR1
6 810 hapoel-haifa 30 ISR1
7 20857 hapoel-raanana 30 ISR1
8 9095 bnei-yehuda-tel-aviv 27 ISR1
9 3785 maccabi-petah-tikva 26 ISR1
10 4769 ihud-bnei-sakhnin 29 ISR1
11 6028 ironi-kiryat-shmona 30 ISR1
12 6025 hapoel-acre 31 ISR1
13 7532 hapoel-kfar-saba 27 ISR1
14 3463 glenavon-fc 40 NIR1
15 21929 ballinamallard-united 34 NIR1
16 3471 linfield-fc 38 NIR1
17 15244 ballymena-united 30 NIR1
18 5594 portadown-fc 32 NIR1
19 1251 cliftonville-fc 34 NIR1
20 21515 dungannon-swifts 26 NIR1
21 3831 coleraine-fc 31 NIR1
22 21532 crusaders-fc 28 NIR1
23 9026 glentoran-fc 38 NIR1
24 40654 warrenpoint-town-fc 35 NIR1
25 8714 carrick-rangers 36 NIR1
26 255 legia-warszawa 36 PL1
27 238 lech-poznan 35 PL1
28 4000 lechia-gdansk 37 PL1
29 2300 jagiellonia-bialystok 41 PL1
... ... ... ... ...
666 2727 oud-heverlee-leuven 31 BE1
667 28643 waasland-beveren 33 BE1
668 27843 bala-town-fc 25 WAL1
669 10734 the-new-saints-fc 29 WAL1
670 9721 port-talbot-town-fc 32 WAL1
671 45574 llandudno-fc 28 WAL1
672 6316 rhyl-football-club 44 WAL1
673 21541 aberystwyth-town-fc 25 WAL1
674 22499 connahs-quay 46 WAL1
675 3649 bangor-city-fc 28 WAL1
676 12566 carmarthen-town-fc 25 WAL1
677 25232 haverfordwest-county 30 WAL1
678 31130 newtown-afc 25 WAL1
679 23088 airbus-uk-broughton-fc 31 WAL1
680 197 ac-sparta-praha 35 TS1
681 941 fc-viktoria-plzen 31 TS1
682 62 sk-slavia-prag 36 TS1
683 5546 fk-mlada-boleslav 38 TS1
684 697 fc-slovan-liberec 38 TS1
685 1322 fk-jablonec 28 TS1
686 2311 sk-sigma-olomouc 32 TS1
687 814 fk-teplice 36 TS1
688 450 dukla-prag 34 TS1
689 2598 1-fk-pribram 38 TS1
690 715 fc-bohemians-prag-1905 29 TS1
691 377 fc-banik-ostrava 44 TS1
692 7975 fc-vysocina-jihlava 35 TS1
693 5544 1-fc-slovacko 32 TS1
694 5225 fc-zbrojovka-brno 30 TS1
695 5545 fc-fastav-zlin 31 TS1

696 rows × 4 columns


In [96]:
country_coeff=pd.read_csv('../data/reference/country_coefficient2.csv').reset_index(drop=True).set_index('Country').rename(index={
        'Bosnia and Herzegovina': 'Bosnia-Herzegovina',
        'Republic of Ireland': 'Ireland',
        'FYR Macedonia': 'Macedonia',
        'Faroe Islands':'Faroe Islands'
    }).join(countryInfo)

In [111]:
countryLeagueMap=nonloans[['fromCountry','fromLeague']].drop_duplicates().rename(columns={'fromLeague':'league','fromCountry':'Country'})


#.set_index('Country').join(countryInfo)


Out[111]:
Country league
0 England Other England
1 England GBJG
2 England GB21
3 England GB1
4 NaN NaN
5 England GB4
8 Ireland Other Ireland
12 Germany Other Germany
17 England GB2
19 England CNAT
24 Scotland Other Scotland
42 United States Other United States
45 Northern Ireland Other Northern Ireland
46 Northern Ireland NIR1
81 England GB3
107 Finland Other Finland
122 Scotland SC1
127 Ireland IR1
133 Denmark Other Denmark
136 Netherlands Other Netherlands
137 Denmark DK1
139 Germany L3
179 United States MLS1
242 Turkey Other Turkey
243 Togo Other Togo
262 Sweden Other Sweden
333 France Other France
414 Iceland Other Iceland
465 Australia Other Australia
486 Ghana Other Ghana
... ... ...
74234 Botsuana Other Botsuana
77213 Turkey TR4A
80911 Tanzania Other Tanzania
81317 Burundi Other Burundi
81322 Rwanda Other Rwanda
81328 Somalia Other Somalia
83340 DDR Other DDR
90857 Swaziland Other Swaziland
91482 Malawi Other Malawi
92766 Martinique Other Martinique
93521 Guadeloupe Other Guadeloupe
99823 Dominican Republic Other Dominican Republic
101584 Gibraltar Other Gibraltar
108667 Mongolia Other Mongolia
120154 Macao Other Macao
145788 Lebanon Other Lebanon
159897 Bermuda Other Bermuda
161516 Cuba Other Cuba
161581 Antigua and Barbuda Other Antigua and Barbuda
172693 Guyana Other Guyana
172698 French Guiana Other French Guiana
189922 Chad Other Chad
208427 Aruba Other Aruba
217643 Guinea-Bissau Other Guinea-Bissau
228627 Madagascar Other Madagascar
229259 Neukaledonien Other Neukaledonien
232634 Tahiti Other Tahiti
241467 St. Lucia Other St. Lucia
254220 Fiji Other Fiji
306281 Guernsey Other Guernsey

313 rows × 2 columns


In [94]:
countryInfo


Out[94]:
National team coeff 2012 coeff 2013 coeff 2014 coeff 2015 coeff total coeff GDP 2010 GDP 2011 GDP 2012 GDP 2013 GDP 2014 Unemployment Corruption Population Growth % federation marketTier Corruption Rank Bribe %
Country
Germany 40236 17.928 14.714 15.857 16.428 64.927 3418.371 3755.549 3535.199 3831.427 3859.547 4.5 81.0 81459000.0 0.32 UEFA 1.0 NaN NaN
Spain 37962 17.714 23.000 20.214 23.928 84.856 1434.257 1495.968 1356.483 1393.476 1406.855 21.4 58.0 46423064.0 -0.06 UEFA 1.0 5.0 2.0
England 35963 16.428 16.785 13.571 14.250 61.034 2409.409 2594.114 2624.291 2680.123 2945.146 5.1 81.0 65081276.0 0.75 UEFA 1.0 17.0 5.0
Portugal 35138 11.750 9.916 9.083 10.500 41.249 238.748 245.120 216.488 224.983 230.012 12.4 63.0 10311000.0 -0.56 UEFA 2.0 6.0 3.0
Belgium 34442 6.500 6.400 9.600 7.400 29.900 485.307 528.721 499.129 524.970 534.672 7.8 77.0 11259000.0 0.52 UEFA 2.0 14.0 4.0
Italy 34345 14.416 14.166 19.000 11.500 59.082 2130.586 2280.315 2076.370 2137.615 2147.952 11.3 44.0 60963000.0 0.49 UEFA 1.0 17.0 5.0
Netherlands 33679 4.214 5.916 6.083 5.750 21.963 837.949 894.576 823.595 853.806 866.354 6.6 87.0 17003777.0 0.37 UEFA 2.0 NaN NaN
France 33599 11.750 8.500 10.916 11.083 42.249 2651.772 2865.304 2688.210 2807.306 2846.889 10.6 70.0 66417000.0 0.39 UEFA 1.0 NaN NaN
Russia 31345 9.750 10.416 9.666 11.500 41.332 1524.915 1904.790 2015.154 2079.134 1857.461 5.8 29.0 144031000.0 0.19 UEFA 2.0 NaN NaN
Switzerland 31254 8.375 7.200 6.900 5.300 27.775 580.696 696.528 665.898 685.871 712.050 3.4 86.0 8265000.0 0.87 UEFA 2.0 21.0 7.0
Austria 30932 2.250 7.800 4.125 3.800 17.975 390.383 429.493 407.801 428.456 437.123 10.6 76.0 8608000.0 0.67 UEFA 2.0 NaN NaN
Croatia 30642 4.375 4.375 6.875 4.500 20.125 59.611 62.172 56.484 57.849 57.159 17.9 51.0 4230000.0 -0.31 UEFA 3.0 14.0 4.0
Bosnia-Herzegovina 30367 1.250 1.500 1.750 1.500 6.000 16.847 18.318 16.906 17.852 17.977 42.8 38.0 3750000.0 -0.64 UEFA 3.0 55.0 28.0
Ukraine 30313 9.500 7.833 10.000 9.800 37.133 136.011 163.307 175.707 179.572 130.660 9.4 27.0 42850000.0 -0.32 UEFA 2.0 69.0 37.0
Czech Republic 29403 8.500 8.000 3.875 7.300 27.675 207.016 227.307 206.751 208.796 205.658 6.2 56.0 10535000.0 -0.06 UEFA 3.0 34.0 15.0
Sweden 29028 5.125 3.200 3.900 4.750 16.975 488.378 563.110 NaN 579.526 570.137 7.5 89.0 9858794.0 1.03 UEFA 3.0 NaN NaN
Poland 28306 2.500 3.125 4.750 5.500 15.875 476.528 524.104 496.687 526.031 546.644 9.8 62.0 38494000.0 0.05 UEFA 3.0 NaN NaN
Romania 28038 6.800 6.875 5.125 2.250 21.050 167.986 186.113 172.041 191.598 199.950 6.7 46.0 19822000.0 -0.41 UEFA 3.0 36.0 17.0
Slovakia 27171 1.500 1.625 2.750 3.750 9.625 89.173 97.621 92.799 97.743 99.971 10.6 51.0 5426000.0 0.13 UEFA 3.0 46.0 21.0
Hungary 27142 3.000 0.875 2.125 1.625 7.625 129.585 139.447 126.825 133.424 137.104 6.2 51.0 9835000.0 -0.28 UEFA 3.0 25.0 12.0
Denmark 27140 3.300 3.800 2.900 5.500 15.500 319.812 341.498 322.277 335.878 340.806 4.5 91.0 5673000.0 0.48 UEFA 2.0 1.0 1.0
Turkey 27033 10.200 6.700 6.000 6.600 29.500 731.539 774.729 788.605 821.918 806.108 10.5 42.0 78214000.0 1.34 UEFA 2.0 46.0 21.0
Ireland 26902 1.000 0.250 2.000 0.700 3.950 218.843 237.990 222.089 232.150 246.438 8.8 75.0 4630000.0 0.35 UEFA 3.0 NaN NaN
Greece 26654 4.400 6.100 6.200 5.400 22.100 300.156 289.068 249.663 242.306 238.023 24.5 46.0 10769000.0 -0.11 UEFA 2.0 48.0 22.0
Norway 26439 4.900 2.600 2.200 7.250 16.950 428.527 498.157 509.705 522.349 500.244 4.6 87.0 5194000.0 1.11 UEFA 3.0 6.0 3.0
Slovenia 25441 3.250 2.625 4.000 1.000 10.875 48.060 51.299 46.288 48.005 49.506 11.7 60.0 2065000.0 0.15 UEFA 3.0 19.0 6.0
Iceland 25388 1.250 2.500 2.500 1.125 7.375 13.261 14.666 14.183 15.330 16.693 3.5 79.0 331000.0 1.22 UEFA 3.0 NaN NaN
Wales 24521 0.500 0.750 0.125 1.500 2.875 NaN NaN NaN NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
Israel 24162 3.250 5.750 1.375 2.250 12.625 NaN NaN NaN NaN NaN 5.4 61.0 NaN NaN UEFA 3.0 25.0 12.0
Scotland 23259 4.300 3.250 4.000 3.000 14.550 NaN NaN NaN NaN NaN NaN NaN NaN NaN UEFA 2.0 NaN NaN
Albania 23216 0.750 2.000 0.875 2.125 5.750 11.927 12.891 12.345 12.916 13.262 17.5 36.0 2887000.0 -0.41 UEFA 3.0 NaN NaN
Montenegro 22971 1.375 1.250 0.750 1.000 4.375 4.118 4.500 4.048 4.419 4.462 17.3 44.0 620000.0 0.00 UEFA 3.0 NaN NaN
Northern Ireland 22961 1.000 0.875 1.375 0.750 4.000 NaN NaN NaN NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN
Serbia 22127 3.000 2.500 2.750 4.250 12.500 39.035 46.488 40.749 45.520 43.866 17.3 40.0 7103000.0 -0.41 UEFA 3.0 51.0 26.0
Finland 21181 2.000 0.500 2.400 1.000 5.900 248.262 273.925 256.849 268.281 271.165 8.2 90.0 5475000.0 0.11 UEFA 3.0 1.0 1.0
Bulgaria 20766 0.750 5.625 4.250 1.000 11.625 48.782 55.799 52.613 54.517 55.837 10.0 41.0 7185000.0 -0.57 UEFA 3.0 23.0 8.0
Armenia 19476 0.875 1.125 0.375 1.625 4.000 NaN NaN NaN NaN NaN 16.6 35.0 3010000.0 -0.03 UEFA 3.0 39.0 18.0
Estonia 19429 0.375 1.000 1.500 1.000 3.875 19.529 22.824 22.673 24.888 25.953 5.2 70.0 1315000.0 0.46 UEFA 3.0 19.0 6.0
Lithuania 19278 1.125 1.250 0.500 0.750 3.625 37.155 43.478 42.828 46.426 48.232 9.4 61.0 2906000.0 -0.85 UEFA 3.0 51.0 26.0
Belarus 18666 4.500 1.750 5.500 5.125 16.875 55.221 59.735 63.615 71.710 76.139 1.0 32.0 9481000.0 0.00 UEFA 3.0 NaN NaN
Georgia 17786 1.500 1.875 1.250 0.625 5.250 NaN NaN NaN NaN NaN NaN 52.0 3707000.0 -1.23 UEFA 3.0 14.0 4.0
Azerbaijan 16941 3.000 2.500 3.625 4.375 13.500 NaN NaN NaN NaN NaN 5.0 29.0 9651000.0 1.23 UEFA 3.0 NaN NaN
Latvia 16911 1.250 1.625 0.250 1.625 4.750 24.112 28.488 28.343 30.838 31.970 9.7 55.0 1979000.0 -0.90 UEFA 3.0 42.0 19.0
Cyprus 16898 4.000 2.750 3.300 3.000 13.050 25.294 27.114 24.954 24.065 23.269 15.8 61.0 876000.0 0.46 UEFA 3.0 42.0 19.0
Moldova 16621 2.250 3.375 1.750 1.250 8.625 5.813 7.018 7.283 7.985 7.944 3.3 33.0 3564000.0 0.48 UEFA 3.0 57.0 29.0
Macedonia 15521 1.250 0.500 1.125 1.500 4.375 9.433 10.659 9.751 10.774 11.342 24.5 42.0 2071000.0 0.15 UEFA 3.0 36.0 17.0
Kazakhstan 14101 1.375 3.125 3.375 4.625 12.500 NaN NaN NaN NaN NaN 5.0 28.0 17543000.0 1.45 UEFA 3.0 62.0 34.0
Luxembourg 13821 1.375 1.500 0.500 0.750 4.125 52.241 59.010 56.323 60.150 62.395 6.7 81.0 570000.0 2.52 UEFA 3.0 NaN NaN
Liechtenstein 12725 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 2.3 NaN 37000.0 0.00 UEFA 3.0 NaN NaN
Faroe Islands 12681 0.500 0.875 1.375 0.375 3.125 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Malta 11310 0.875 0.875 0.125 0.875 2.750 8.757 9.604 9.289 10.056 10.582 5.1 56.0 425000.0 0.47 UEFA 3.0 NaN NaN
Andorra 8520 0.000 0.333 0.500 0.166 0.999 NaN NaN NaN NaN NaN 4.0 NaN 78000.0 1.30 UEFA 3.0 NaN NaN
San Marino 8110 0.000 0.333 0.000 0.000 0.333 2.143 2.056 1.802 1.802 1.786 7.0 NaN 33000.0 0.00 UEFA 3.0 NaN NaN
Gibraltar 7300 NaN NaN 0.250 0.750 1.000 NaN NaN NaN NaN NaN NaN NaN NaN NaN UEFA 3.0 NaN NaN