In [1]:
from flags import Flags
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline  

import sys
sys.path.insert(1,'../..')
from src import PositionElgibility

In [2]:
projections = pd.read_csv('../../data/raw/projections-espn-2017.csv')

In [3]:
projections['position_elgibility'] = projections['position_elgibility'].apply(lambda x: PositionElgibility(x))

In [4]:
projections[projections['position_elgibility'] & PositionElgibility.catcher]


Out[4]:
player_id name position_elgibility at_bats runs home_runs runs_batted_in batter_walks batter_strikeouts stolen_bases ... games_started innings_pitched walks strikeouts wins saves holds earned_run_avg walks_hits_per_inning strikeouts_per_9
52 2380 Buster Posey (((PositionElgibility.catcher))) 514.0 75.0 16.0 82.0 56.0 61.0 4.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
72 3557 Gary Sanchez (((PositionElgibility.catcher))) 453.0 55.0 25.0 69.0 35.0 108.0 7.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
81 2816 Jonathan Lucroy (((PositionElgibility.catcher))) 514.0 71.0 19.0 77.0 51.0 86.0 4.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
87 5020 Willson Contreras (((PositionElgibility.catcher)), ((PositionElg... 428.0 53.0 15.0 56.0 43.0 87.0 5.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
95 4653 J.T. Realmuto (((PositionElgibility.catcher))) 510.0 58.0 10.0 50.0 28.0 92.0 12.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
103 3389 Yasmani Grandal (((PositionElgibility.catcher))) 391.0 50.0 23.0 65.0 63.0 112.0 1.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
109 5444 Evan Gattis (((PositionElgibility.catcher)), ((PositionElg... 409.0 51.0 25.0 65.0 31.0 102.0 1.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
111 3590 Salvador Perez (((PositionElgibility.catcher))) 518.0 54.0 20.0 65.0 19.0 100.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
121 1212 Brian McCann (((PositionElgibility.catcher)), ((PositionElg... 415.0 50.0 16.0 59.0 41.0 90.0 1.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
127 2122 Matt Wieters (((PositionElgibility.catcher))) 411.0 46.0 16.0 61.0 31.0 90.0 1.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
144 1268 Russell Martin (((PositionElgibility.catcher))) 440.0 63.0 21.0 74.0 60.0 128.0 3.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
146 1019 Yadier Molina (((PositionElgibility.catcher))) 488.0 45.0 7.0 52.0 34.0 60.0 2.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
154 2198 Welington Castillo (((PositionElgibility.catcher))) 399.0 38.0 14.0 59.0 32.0 109.0 1.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
159 3494 Stephen Vogt (((PositionElgibility.catcher)), ((PositionElg... 473.0 55.0 15.0 61.0 40.0 82.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
164 5728 Tom Murphy (((PositionElgibility.catcher))) 215.0 28.0 11.0 33.0 10.0 64.0 2.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
169 2089 Francisco Cervelli (((PositionElgibility.catcher))) 378.0 46.0 3.0 35.0 53.0 84.0 4.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
174 2467 Wilson Ramos (((PositionElgibility.catcher))) 336.0 33.0 12.0 49.0 21.0 63.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
179 5152 Mike Zunino (((PositionElgibility.catcher))) 314.0 32.0 14.0 41.0 23.0 110.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
185 4285 Cameron Rupp (((PositionElgibility.catcher))) 403.0 36.0 16.0 50.0 28.0 124.0 1.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
188 3000 Derek Norris (((PositionElgibility.catcher))) 350.0 44.0 11.0 41.0 32.0 106.0 5.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
196 4583 Yan Gomes (((PositionElgibility.catcher))) 276.0 30.0 10.0 40.0 11.0 74.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
200 2984 Travis d'Arnaud (((PositionElgibility.catcher))) 259.0 31.0 7.0 26.0 21.0 49.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
210 2263 Devin Mesoraco (((PositionElgibility.catcher))) 233.0 27.0 10.0 36.0 24.0 57.0 1.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
217 4520 James McCann (((PositionElgibility.catcher))) 393.0 34.0 9.0 46.0 23.0 107.0 2.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
225 2472 Jason Castro (((PositionElgibility.catcher))) 352.0 44.0 11.0 39.0 39.0 110.0 1.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
232 4576 Sandy Leon (((PositionElgibility.catcher))) 325.0 35.0 7.0 35.0 26.0 82.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
236 4599 Blake Swihart (((PositionElgibility.catcher))) 175.0 22.0 2.0 18.0 16.0 40.0 3.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
237 4530 Jett Bandy (((PositionElgibility.catcher))) 364.0 40.0 11.0 47.0 17.0 78.0 3.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
241 4644 Austin Hedges (((PositionElgibility.catcher))) 374.0 37.0 11.0 49.0 14.0 77.0 1.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
244 4536 Andrew Susac (((PositionElgibility.catcher))) 56.0 6.0 1.0 6.0 4.0 17.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
247 3642 Tucker Barnhart (((PositionElgibility.catcher))) 260.0 22.0 4.0 29.0 24.0 48.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
251 4471 Chris Herrmann (((PositionElgibility.catcher))) 307.0 39.0 8.0 40.0 27.0 90.0 7.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
255 1991 Nick Hundley (((PositionElgibility.catcher))) 181.0 16.0 4.0 21.0 13.0 43.0 1.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
260 4214 Jorge Alfaro (((PositionElgibility.catcher))) 61.0 6.0 2.0 6.0 2.0 20.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN
266 1466 Miguel Montero (((PositionElgibility.catcher))) 166.0 19.0 6.0 24.0 24.0 42.0 0.0 ... NaN NaN NaN 0.0 0.0 0.0 NaN 0.0 0.0 NaN

35 rows × 25 columns

Calculating hits from average


In [5]:
projections['hits'] = projections['batting_avg'] * projections['at_bats']

Calculating earned runs from ERA


In [6]:
projections['earned_runs'] = (projections['innings_pitched'] * projections['earned_run_avg']) / 9

Calculating hits against from WHIP


In [7]:
projections['hits_against'] = (projections['walks_hits_per_inning'] * projections['innings_pitched']) - projections['walks']

Calculating Standing Gain Points


In [8]:
razz = pd.read_csv('../../data/raw/razzball-2016.csv')

In [9]:
from scipy.stats import linregress

l = pd.DataFrame(razz[razz['League'] == 'All Hail Beddict Tha God'])
razz['run_rank'] = razz.groupby('League')['R'].rank(ascending=False)

In [10]:
razz.sort_values('run_rank')


Out[10]:
# Team League RCL PTS Lg PTS Lg Index Master PTS R HR RBI ... SV ERA WHIP K IP K/9 AB GS Moves run_rank
0 1 Team Levy All Hail Beddict Tha God 114.6 120.0 98 113.3 1169 375 1172 ... 177 3.14 1.15 1437 1368 9.5 7836 155 345 1.0
131 132 Vinyl Ross 2016 Shades of Grey 90.4 90.5 100 90.1 1178 377 1213 ... 131 3.74 1.27 1381 1340 9.3 8009 175 176 1.0
128 129 Vin Reds The Third Greatest 90.8 90.5 100 91.2 1160 332 1123 ... 144 3.58 1.22 1423 1447 8.9 7924 186 238 1.0
261 262 Thomaston Herbivore Club Prospecter Ralph`s Cavern 80.1 80.5 101 78.9 1102 285 963 ... 157 3.48 1.20 1426 1396 9.2 7428 180 119 1.0
113 114 Buchard Black Sox Sultans of Swat 92.1 95.0 100 89.2 1123 323 1036 ... 69 3.68 1.22 1351 1350 9.0 7402 180 32 1.0
269 270 The People’s Champ The Heat Is On 79.5 75.0 104 79.5 1123 301 1017 ... 157 3.89 1.27 1295 1307 8.9 7453 139 323 1.0
105 106 Team Albright Razzball `Perty `Perts 92.6 85.5 107 90.8 1167 308 1111 ... 128 3.69 1.27 1603 1550 9.3 8061 185 622 1.0
270 271 naples cardinals Mighty Minions 79.5 78.5 100 80.7 1183 319 1136 ... 49 3.83 1.25 1260 1285 8.8 7947 181 62 1.0
202 203 Barry Feete League Of Shadows 84.5 85.5 98 85.6 1171 297 1074 ... 111 3.62 1.26 1364 1345 9.1 7851 180 82 1.0
96 97 Vindaloo Ross RCL Lords of the Diamond 93.3 103.0 94 92.2 1126 351 1108 ... 167 3.32 1.24 1396 1443 8.7 7876 185 217 1.0
94 95 F0rce Ch0ke (In October) The Force Awakens 93.4 94.0 101 92.0 1181 328 1092 ... 146 3.99 1.27 1491 1473 9.1 7678 186 254 1.0
92 93 Vin Reigns Baba Booey 93.6 99.5 97 92.1 1175 339 1160 ... 164 3.65 1.24 1429 1376 9.3 8225 181 231 1.0
91 92 The Robot Maids The Greatest 93.9 96.0 99 93.3 1147 301 1072 ... 150 3.72 1.21 1548 1430 9.7 7573 180 252 1.0
87 88 CP Winos Albright`s E-Cougar-Harmony.com 94.2 95.0 100 92.9 1140 335 1084 ... 185 3.27 1.20 1279 1397 8.2 8081 159 256 1.0
84 85 Donkeycorn Apocalypse 4 12 Monkeys Clicking 94.3 93.0 101 93.7 1253 353 1164 ... 119 3.62 1.23 1378 1371 9.0 8075 188 465 1.0
83 84 Light Tower Power Nico Sux Dico 94.5 94.0 100 94.7 1161 324 1092 ... 147 3.65 1.23 1465 1450 9.1 7973 184 245 1.0
334 335 Channel 4 News Team Take on the JayWrong #4 75.7 82.0 96 74.6 1104 286 1011 ... 131 3.80 1.26 1342 1345 9.0 7380 180 93 1.0
81 82 Ra’zbahl Al Ghul ECFBL 94.6 84.0 109 93.7 1242 343 1095 ... 81 3.54 1.20 1248 1331 8.4 7905 181 174 1.0
673 674 Kubels And Bits Enemies of Beddict 56.1 65.0 93 53.7 1101 321 1040 ... 56 4.08 1.32 985 1077 8.2 7014 159 7 1.0
75 76 Vin and Angela Center Field 95.0 99.0 98 94.2 1248 362 1101 ... 179 3.96 1.30 1344 1446 8.4 8186 186 275 1.0
73 74 London Smokey The Viz vs. The Commenters 95.1 94.5 101 94.0 1191 355 1099 ... 129 3.48 1.18 1172 1250 8.4 8106 166 126 1.0
72 73 AK FortySevens Night of the Living Zombinos 95.1 88.0 106 93.6 1227 361 1157 ... 178 3.76 1.25 1501 1585 8.5 8232 187 715 1.0
71 72 Up North2 Muscle Car Fanatics 95.1 96.0 101 92.5 1133 286 1091 ... 140 3.71 1.27 1535 1473 9.4 7856 184 309 1.0
280 281 ISLANDERS FAN BOBBY Take on the Jaywrong 5 79.0 84.5 97 76.8 1135 330 1154 ... 80 4.17 1.26 1286 1354 8.5 7562 181 130 1.0
66 67 The Education of Dr Z Take on the JayWrong 3 95.7 99.5 100 91.9 1152 351 1190 ... 131 3.53 1.20 1327 1330 9.0 7762 180 93 1.0
332 333 Breaking Balls DeadPool 75.8 80.0 98 74.2 1143 329 1067 ... 118 4.18 1.32 1412 1371 9.3 7898 188 148 1.0
133 134 Vinspired Ross Smoke Show 90.3 90.0 101 89.5 1222 339 1141 ... 167 3.98 1.29 1407 1446 8.8 8091 187 257 1.0
135 136 Vin Rains Opening Day 90.2 89.5 101 89.0 1216 348 1132 ... 123 3.51 1.29 1331 1390 8.6 7960 173 241 1.0
136 137 florida cardinals Trout Mask Replica 90.1 91.0 101 88.2 1157 334 1119 ... 59 3.53 1.23 1251 1299 8.7 7817 180 81 1.0
250 251 Cruz it or lose it RCL FIPping the Bird 2016 80.8 88.5 94 80.4 1118 325 1108 ... 84 3.90 1.24 1314 1389 8.5 7566 180 92 1.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
773 774 Team Rogers All Hail Beddict Tha God 49.4 51.5 98 49.1 870 250 848 ... 29 3.64 1.20 1106 1261 7.9 6163 180 30 12.0
960 961 Team Rogers Straight BESTBUY Homie 32.7 20.5 99 45.2 856 232 856 ... 60 3.54 1.10 1009 973 9.3 6194 126 15 12.0
847 848 Catchin Spitters Razzballero1 44.2 43.0 101 44.5 904 263 869 ... 59 3.68 1.27 1239 1300 8.6 6395 183 17 12.0
857 858 Kipnis Everdeen Nico Sux Dico 43.5 43.0 100 43.8 753 191 734 ... 47 3.53 1.18 1174 1169 9.0 5552 149 1 12.0
957 958 Team Ervin My Church 33.1 29.0 101 36.7 894 290 921 ... 0 4.03 1.22 1033 1130 8.2 6019 180 0 12.0
955 956 No Use For A Name FCL 33.5 27.0 107 37.2 883 256 922 ... 101 4.09 1.29 801 819 8.8 6350 85 11 12.0
948 949 Team Meeks 2016 Shades of Grey 34.4 33.5 100 35.2 771 270 796 ... 12 3.98 1.23 1157 1161 9.0 5266 180 2 12.0
943 944 King Kang Razzamatazzberry League 35.2 37.0 99 34.2 809 243 857 ... 76 3.77 1.29 1080 1097 8.9 6159 154 3 12.0
940 941 The Oil Can Dans Matt Stairs` Fantasy Review 35.4 36.0 100 35.0 928 231 821 ... 77 4.02 1.33 937 1030 8.2 6590 140 2 12.0
937 938 Team Rogers RCL 1000 35.7 25.5 101 45.4 886 237 833 ... 48 3.49 1.20 968 971 9.0 6205 135 19 12.0
935 936 InDaButt UpchuckYoMouth 12 Monkeys Clicking 35.8 32.5 101 38.5 747 172 655 ... 60 3.87 1.22 1227 1239 8.9 5299 181 8 12.0
930 931 Team Longfellow Razzball `Perty `Perts 36.3 28.5 107 41.2 905 242 897 ... 77 3.71 1.20 1080 1160 8.4 6442 142 7 12.0
928 929 6th District Diickin Around 36.4 33.0 102 38.8 829 223 861 ... 34 3.86 1.27 1122 1267 8.0 6198 181 12 12.0
927 928 Team Patterson The Greatest 36.5 38.0 99 35.6 699 213 709 ... 90 3.56 1.18 1062 1025 9.3 5226 127 1 12.0
926 927 Extended Training The Third Greatest 36.7 35.5 100 37.9 896 253 934 ... 74 4.00 1.26 1118 1241 8.1 6282 181 33 12.0
855 856 Don Mattingly’s Sideburns Cougs R Us 43.6 35.0 106 48.9 927 280 958 ... 72 3.60 1.21 1227 1231 9.0 6946 177 50 12.0
390 391 I Can Play– Centerfield ECFBL 72.4 58.5 109 78.4 1003 280 999 ... 100 3.66 1.23 1429 1516 8.5 7208 188 148 12.0
914 915 The Sinkholes That`ll do Puig 38.2 34.5 102 41.0 887 263 886 ... 0 3.49 1.17 935 1109 7.6 6476 181 9 12.0
913 914 House of Pain Razzball Lurkers 38.2 30.0 104 44.7 965 228 946 ... 21 3.81 1.26 1105 1133 8.8 6735 164 12 12.0
405 406 This Lil’ Puigy Went To Market Effectively Hide my Thunder 71.2 68.0 102 72.6 947 300 929 ... 144 3.10 1.09 1400 1325 9.5 6913 150 80 12.0
904 905 Team Poretsky All Summer Long 39.1 39.0 101 38.8 731 203 700 ... 64 3.70 1.26 1223 1224 9.0 5166 169 3 12.0
899 900 Wacha Wacha DFSers Anonymous 39.5 29.0 107 47.0 932 244 971 ... 70 3.66 1.27 1236 1184 9.4 6870 152 98 12.0
895 896 Hall of Shamers Center Field 40.0 40.5 98 40.7 838 225 826 ... 54 3.42 1.12 1145 1109 9.3 6083 159 23 12.0
889 890 Team MrWolf Mighty Minions 40.5 40.5 100 40.6 833 263 855 ... 168 3.56 1.24 1006 1032 8.8 6324 117 19 12.0
883 884 Richard Pole’s Beavers Grey haired sack o balls 41.1 45.0 97 39.4 812 223 858 ... 0 3.72 1.19 1048 1125 8.4 5944 180 1 12.0
475 476 Heavy on the Anchovies Trout Mask Replica 67.1 65.0 101 68.6 910 303 954 ... 100 3.48 1.13 1366 1343 9.2 6438 180 16 12.0
862 863 Daddy Bullpens Smoke Show 42.8 41.0 101 44.0 784 219 759 ... 56 3.59 1.19 1164 1176 8.9 5772 151 7 12.0
1018 1019 Ill Will Phil Hill Riverboat Fantasy 15.5 12.0 103 18.6 639 167 673 ... 2 3.89 1.30 835 1087 6.9 5071 181 67 12.0
915 916 Hoogs Your Daddy RCL FIPping the Bird 2016 37.9 44.0 94 35.5 756 169 638 ... 40 3.90 1.23 1194 1217 8.8 5221 180 9 12.0
1019 1020 Trailerpark Romeo Night of the Living Zombinos 15.1 10.0 106 19.2 734 197 749 ... 16 4.01 1.28 1071 1123 8.6 5837 182 38 12.0

1020 rows × 23 columns


In [11]:
razz.plot.scatter(y='R', x='run_rank')


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

In [12]:
slope = linregress(razz['run_rank'], razz['R'])
slope[0]


Out[12]:
-25.968797596015314

In [13]:
run_sgp = abs(slope[0])
run_sgp


Out[13]:
25.968797596015314

Final product

Here is a function which, given a data frame and a stat name, calculates the SGP for that stat.


In [14]:
def stat_sgp(df, stat, asc=False):
    return linregress(df.groupby('League')[stat].rank(ascending=asc), df[stat])[0] * -1

r_sgp = stat_sgp(razz, 'R')
hr_sgp = stat_sgp(razz, 'HR')
rbi_sgp = stat_sgp(razz, 'RBI')
sb_sgp = stat_sgp(razz, 'SB')
avg_sgp = stat_sgp(razz, 'AVG')
w_sgp = stat_sgp(razz, 'W')
sv_sgp = stat_sgp(razz, 'SV')
era_sgp = stat_sgp(razz, 'ERA', True)
whip_sgp = stat_sgp(razz, 'WHIP', True)
k_sgp = stat_sgp(razz, 'K')

In [15]:
era_sgp


Out[15]:
-0.077205639841688656

Player SGP Added (SGPA)

Batting SGPA


In [16]:
f = projections.loc[0,:]
f


Out[16]:
player_id                                             3280
name                                            Mike Trout
position_elgibility      (((PositionElgibility.outfield)))
at_bats                                                565
runs                                                   116
home_runs                                               33
runs_batted_in                                          99
batter_walks                                           104
batter_strikeouts                                      151
stolen_bases                                            23
batting_avg                                          0.301
on_base_percent                                      0.415
slugging_avg                                         0.561
on_base_plus_slugging                                0.977
games                                                  NaN
games_started                                          NaN
innings_pitched                                        NaN
walks                                                  NaN
strikeouts                                               0
wins                                                     0
saves                                                    0
holds                                                  NaN
earned_run_avg                                           0
walks_hits_per_inning                                    0
strikeouts_per_9                                       NaN
hits                                               170.065
earned_runs                                            NaN
hits_against                                           NaN
Name: 0, dtype: object

In [17]:
r_sgp


Out[17]:
25.968797596015314

In [18]:
num_batters = 13
num_teams = 10

projections['runs_sgpa'] = projections['runs'] / r_sgp
projections['home_runs_sgpa'] = projections['home_runs'] / hr_sgp
projections['runs_batted_in_sgpa'] = projections['runs_batted_in'] / rbi_sgp
projections['stolen_bases_sgpa'] = projections['stolen_bases'] / sb_sgp

avg_h = projections.sort_values('hits', ascending=False).head(num_batters*num_teams).loc[:,'hits'].mean() * (num_batters -1)
avg_h


Out[18]:
1878.7687384615385

In [19]:
avg_ab = projections.sort_values('at_bats', ascending=False).head(num_batters*num_teams).loc[:,'at_bats'].mean() * (num_batters -1)
avg_ab


Out[19]:
6860.8615384615387

In [20]:
avg_avg = avg_h / avg_ab
avg_avg


Out[20]:
0.27383860291149797

In [21]:
with_trout = (avg_h + f['hits']) / (avg_ab + f['at_bats'])
projections['batting_avg_sgpa'] = (((avg_h + projections['hits']) / (avg_ab + projections['at_bats'])) - avg_avg) / avg_sgp

Pitching SGPA


In [22]:
projections['wins_sgpa'] = projections['wins'] / w_sgp
projections['saves_sgpa'] = projections['saves'] / sv_sgp
projections['strikeouts_sgpa'] = projections['strikeouts'] / k_sgp

In [23]:
num_pitchers = 9

avg_er = projections.sort_values(['innings_pitched', 'earned_runs'], ascending=[False, True]).head(num_pitchers*num_teams).loc[:,'earned_runs'].mean() * (num_pitchers -1)
avg_er


Out[23]:
608.1860740740741

In [24]:
avg_ip = projections.sort_values('innings_pitched', ascending=False).head(num_pitchers*num_teams).loc[:,'innings_pitched'].mean() * (num_pitchers -1)
avg_ip


Out[24]:
1496.6222222222223

In [25]:
avg_era = (avg_er / avg_ip) * 9
avg_era


Out[25]:
3.6573522599037833

In [26]:
projections['earned_run_avg_sgpa'] = (((avg_er + projections['earned_runs']) / (avg_ip + projections['innings_pitched']) * 9) - avg_era) / era_sgp

In [27]:
avg_bb = projections.sort_values(['innings_pitched', 'walks'], ascending=[False, True]).head(num_pitchers*num_teams).loc[:,'walks'].mean() * (num_pitchers -1)
avg_bb


Out[27]:
428.26666666666665

In [28]:
avg_ha =projections.sort_values(['innings_pitched', 'hits_against'], ascending=[False, True]).head(num_pitchers*num_teams).loc[:,'hits_against'].mean() * (num_pitchers - 1)
avg_ha


Out[28]:
1400.144888888889

In [29]:
avg_whip = (avg_bb + avg_ha) / avg_ip
avg_whip


Out[29]:
1.2216921066698343

In [30]:
whip_sgp


Out[30]:
-0.015328138672444699

In [31]:
projections['walks_hits_per_inning_sgpa'] = ((((avg_bb + projections['walks']) + (avg_ha + projections['hits_against'])) / (avg_ip + projections['innings_pitched'])) - avg_whip) / whip_sgp

Total SGPA


In [32]:
projections['total_sgpa'] = (projections['runs_sgpa'].fillna(0) + 
    projections['home_runs_sgpa'].fillna(0) +
    projections['runs_batted_in_sgpa'].fillna(0) +
    projections['stolen_bases_sgpa'].fillna(0) +
    projections['batting_avg_sgpa'].fillna(0) +
    projections['wins_sgpa'].fillna(0) +
    projections['saves_sgpa'].fillna(0) +
    projections['strikeouts_sgpa'].fillna(0) +
    projections['earned_run_avg_sgpa'].fillna(0))
projections


Out[32]:
player_id name position_elgibility at_bats runs home_runs runs_batted_in batter_walks batter_strikeouts stolen_bases ... home_runs_sgpa runs_batted_in_sgpa stolen_bases_sgpa batting_avg_sgpa wins_sgpa saves_sgpa strikeouts_sgpa earned_run_avg_sgpa walks_hits_per_inning_sgpa total_sgpa
0 3280 Mike Trout (((PositionElgibility.outfield))) 565.0 116.0 33.0 99.0 104.0 151.0 23.0 ... 3.335832 4.000585 2.413494 1.041297 0.000000 0.000000 0.000000 NaN NaN 15.258107
1 4144 Jose Altuve (((PositionElgibility.second_base))) 639.0 96.0 17.0 80.0 49.0 65.0 29.0 ... 1.718459 3.232796 3.043101 2.153467 0.000000 0.000000 0.000000 NaN NaN 13.844567
2 5534 Mookie Betts (((PositionElgibility.outfield))) 635.0 110.0 25.0 96.0 50.0 82.0 24.0 ... 2.527145 3.879356 2.518428 1.543542 0.000000 0.000000 0.000000 NaN NaN 14.704323
3 5675 Kris Bryant (((PositionElgibility.third_base)), ((Position... 599.0 102.0 35.0 104.0 76.0 174.0 13.0 ... 3.538004 4.202635 1.364149 0.411122 0.000000 0.000000 0.000000 NaN NaN 13.443700
4 3486 Paul Goldschmidt (((PositionElgibility.first_base))) 570.0 104.0 25.0 98.0 111.0 150.0 26.0 ... 2.527145 3.960175 2.728297 1.011155 0.000000 0.000000 0.000000 NaN NaN 14.231579
5 3734 Nolan Arenado (((PositionElgibility.third_base))) 619.0 107.0 41.0 127.0 54.0 102.0 2.0 ... 4.144518 5.132064 0.209869 0.965790 0.000000 0.000000 0.000000 NaN NaN 14.572571
6 3559 Manny Machado (((PositionElgibility.third_base)), ((Position... 637.0 101.0 36.0 90.0 54.0 117.0 6.0 ... 3.639089 3.636896 0.629607 0.777450 0.000000 0.000000 0.000000 NaN NaN 12.572325
7 2197 Josh Donaldson (((PositionElgibility.third_base))) 589.0 119.0 36.0 107.0 95.0 123.0 7.0 ... 3.639089 4.323865 0.734542 0.404801 0.000000 0.000000 0.000000 NaN NaN 13.684719
8 3215 Anthony Rizzo (((PositionElgibility.first_base))) 590.0 96.0 33.0 104.0 78.0 113.0 7.0 ... 3.335832 4.202635 0.734542 0.565031 0.000000 0.000000 0.000000 NaN NaN 12.534784
9 3390 Bryce Harper (((PositionElgibility.outfield))) 521.0 95.0 29.0 89.0 114.0 127.0 16.0 ... 2.931489 3.596486 1.678952 0.147990 0.000000 0.000000 0.000000 NaN NaN 12.013153
10 3546 Charlie Blackmon (((PositionElgibility.outfield))) 607.0 103.0 25.0 76.0 42.0 105.0 28.0 ... 2.527145 3.071156 2.938166 1.317190 0.000000 0.000000 0.000000 NaN NaN 13.819956
11 897 Miguel Cabrera (((PositionElgibility.first_base))) 593.0 90.0 32.0 104.0 77.0 117.0 0.0 ... 3.234746 4.202635 0.000000 1.329313 0.000000 0.000000 0.000000 NaN NaN 12.232392
12 6203 Trea Turner (((PositionElgibility.second_base)), ((Positio... 632.0 89.0 15.0 59.0 40.0 146.0 43.0 ... 1.516287 2.384187 4.512184 -0.078141 0.000000 0.000000 0.000000 NaN NaN 11.761707
13 5148 Carlos Correa (((PositionElgibility.short_stop))) 595.0 81.0 24.0 101.0 72.0 136.0 16.0 ... 2.426060 4.081405 1.678952 0.127122 0.000000 0.000000 0.000000 NaN NaN 11.432666
14 5187 Corey Seager (((PositionElgibility.short_stop))) 631.0 99.0 24.0 75.0 49.0 131.0 4.0 ... 2.426060 3.030746 0.419738 0.940498 0.000000 0.000000 0.000000 NaN NaN 10.629309
15 3274 Starling Marte (((PositionElgibility.outfield))) 589.0 85.0 15.0 64.0 30.0 132.0 45.0 ... 1.516287 2.586237 4.722053 0.803172 0.000000 0.000000 0.000000 NaN NaN 12.900908
16 1612 Joey Votto (((PositionElgibility.first_base))) 551.0 94.0 28.0 85.0 116.0 125.0 8.0 ... 2.830403 3.434846 0.839476 1.092329 0.000000 0.000000 0.000000 NaN NaN 11.816783
17 4605 Francisco Lindor (((PositionElgibility.short_stop))) 609.0 98.0 14.0 76.0 54.0 95.0 21.0 ... 1.415201 3.071156 2.203625 1.033619 0.000000 0.000000 0.000000 NaN NaN 11.497361
18 2487 Freddie Freeman (((PositionElgibility.first_base))) 593.0 97.0 28.0 88.0 88.0 163.0 5.0 ... 2.830403 3.556076 0.524673 0.567676 0.000000 0.000000 0.000000 NaN NaN 11.214079
19 4087 Xander Bogaerts (((PositionElgibility.short_stop))) 627.0 101.0 17.0 82.0 51.0 120.0 11.0 ... 1.718459 3.313616 1.154280 0.892843 0.000000 0.000000 0.000000 NaN NaN 10.968480
20 2013 Daniel Murphy (((PositionElgibility.first_base)), ((Position... 547.0 83.0 22.0 101.0 36.0 52.0 4.0 ... 2.223888 4.081405 0.419738 1.717491 0.000000 0.000000 0.000000 NaN NaN 11.638665
21 3468 Brian Dozier (((PositionElgibility.second_base))) 615.0 104.0 35.0 87.0 68.0 139.0 16.0 ... 3.538004 3.515666 1.678952 -0.988134 0.000000 0.000000 0.000000 NaN NaN 11.749294
22 1600 Carlos Gonzalez (((PositionElgibility.outfield))) 551.0 83.0 29.0 94.0 44.0 126.0 3.0 ... 2.931489 3.798536 0.314804 0.567917 0.000000 0.000000 0.000000 NaN NaN 10.808888
23 969 Edwin Encarnacion (((PositionElgibility.first_base)), ((Position... 573.0 100.0 39.0 115.0 83.0 126.0 2.0 ... 3.942347 4.647145 0.209869 -0.110247 0.000000 0.000000 0.000000 NaN NaN 12.539889
24 3756 Christian Yelich (((PositionElgibility.outfield))) 581.0 82.0 16.0 82.0 74.0 135.0 14.0 ... 1.617373 3.313616 1.469083 0.793115 0.000000 0.000000 0.000000 NaN NaN 10.350823
25 1139 Robinson Cano (((PositionElgibility.second_base))) 628.0 92.0 29.0 90.0 47.0 95.0 2.0 ... 2.931489 3.636896 0.209869 0.598372 0.000000 0.000000 0.000000 NaN NaN 10.919338
26 1659 Ryan Braun (((PositionElgibility.outfield))) 505.0 76.0 27.0 84.0 46.0 104.0 15.0 ... 2.729317 3.394436 1.574018 0.316483 0.000000 0.000000 0.000000 NaN NaN 10.940843
27 2971 Giancarlo Stanton (((PositionElgibility.outfield))) 518.0 76.0 37.0 99.0 68.0 170.0 4.0 ... 3.740175 4.000585 0.419738 -0.666362 0.000000 0.000000 0.000000 NaN NaN 10.420726
28 3527 J.D. Martinez (((PositionElgibility.outfield))) 580.0 83.0 30.0 91.0 53.0 167.0 4.0 ... 3.032574 3.677306 0.419738 0.359822 0.000000 0.000000 0.000000 NaN NaN 10.685583
29 5600 Jose Abreu (((PositionElgibility.first_base))) 609.0 74.0 29.0 101.0 48.0 131.0 1.0 ... 2.931489 4.081405 0.104935 0.622823 0.000000 0.000000 0.000000 NaN NaN 10.590225
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
420 4465 Joe Kelly (((PositionElgibility.starting_pitcher)), ((Po... NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 0.919412 0.000000 1.603954 -0.001406 -0.155998 2.521960
421 6783 Robert Gsellman (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 2.451765 0.000000 2.784642 -0.059473 -0.502461 5.176934
422 6759 Joe Musgrove (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 3.064706 0.000000 3.230185 -0.079254 0.265664 6.215637
423 4957 Carter Capps (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 0.612941 0.494854 1.292074 0.354817 0.211693 2.754686
424 2952 Tyler Chatwood (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 3.371177 0.000000 2.650980 -0.502713 -1.415426 5.519443
425 6328 Jose De Leon (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 0.919412 0.000000 1.158411 -0.113767 -0.057390 1.964056
426 3554 Mike Montgomery (((PositionElgibility.starting_pitcher)), ((Po... NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 2.451765 0.000000 2.851474 -0.003218 -0.479443 5.300020
427 5167 Grant Dayton (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 1.225883 0.082476 1.715340 0.583914 0.610873 3.607612
428 4662 Blake Treinen (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 1.225883 1.072183 1.225243 0.359616 -0.133112 3.882924
429 4522 Wei-Yin Chen (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 2.451765 0.000000 2.918305 -0.613988 0.010842 4.756083
430 4502 Dan Otero (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 1.225883 0.000000 1.047026 0.464732 0.284276 2.737640
431 5083 Hunter Strickland (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 1.225883 0.329903 1.492568 0.583914 0.390433 3.632267
432 1145 Francisco Liriano (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 3.064706 0.000000 3.720282 -0.624454 -0.654200 6.160535
433 1107 Joe Blanton (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 1.225883 0.000000 1.693063 0.332142 0.285467 3.251087
434 2977 Bryan Shaw (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 1.225883 0.000000 1.358905 0.283027 -0.022892 2.867815
435 3586 David Phelps (((PositionElgibility.starting_pitcher)), ((Po... NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 1.225883 0.000000 1.626231 -0.008411 -0.362788 2.843703
436 6900 Chad Kuhl (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 2.451765 0.000000 1.982665 -0.203820 -0.244727 4.230611
437 3384 Greg Holland (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 0.919412 0.000000 1.292074 0.310511 -0.076095 2.521997
438 3383 Josh Tomlin (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 3.064706 0.000000 3.007414 -1.049492 0.158677 5.022628
439 3693 Tyler Skaggs (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 2.758236 0.000000 3.029691 -0.003124 -0.524816 5.784803
440 5705 Carl Edwards (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 0.612941 0.000000 1.113857 0.278836 -0.031848 2.005634
441 658 R.A. Dickey (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 2.758236 0.000000 3.252462 -0.667003 -0.840938 5.343695
442 7331 Luis Perdomo (((PositionElgibility.starting_pitcher)), ((Po... NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 0.000000 0.000000 0.000000 -0.000000 -0.000000 0.000000
443 1277 Edinson Volquez (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 3.064706 0.000000 3.230185 -0.545247 -1.279748 5.749644
444 2359 Hector Rondon (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 0.919412 0.164951 1.269797 0.358802 0.515308 2.712962
445 3257 Lance Lynn (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 2.451765 0.000000 2.561871 -0.082517 -0.645244 4.931119
446 4099 Mychal Givens (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 1.225883 0.082476 1.938111 0.462150 0.035012 3.708619
447 5702 Daniel Norris (((PositionElgibility.starting_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 2.451765 0.000000 2.851474 -0.527677 -0.625573 4.775562
448 2033 Jesse Chavez (((PositionElgibility.starting_pitcher)), ((Po... NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 2.451765 0.000000 3.007414 -0.732872 -0.573607 4.726307
449 3950 Drew Hutchison (((PositionElgibility.relief_pitcher))) NaN 0.0 0.0 0.0 NaN NaN 0.0 ... 0.000000 0.000000 0.000000 NaN 1.532353 0.000000 1.871280 -0.205488 -0.176896 3.198145

450 rows × 39 columns

Top ten players by value add


In [33]:
projections.sort_values('total_sgpa', ascending=False).loc[:,['name', 'position_elgibility', 'total_sgpa']].head(10)


Out[33]:
name position_elgibility total_sgpa
0 Mike Trout (((PositionElgibility.outfield))) 15.258107
2 Mookie Betts (((PositionElgibility.outfield))) 14.704323
5 Nolan Arenado (((PositionElgibility.third_base))) 14.572571
4 Paul Goldschmidt (((PositionElgibility.first_base))) 14.231579
270 Clayton Kershaw (((PositionElgibility.starting_pitcher))) 13.858970
1 Jose Altuve (((PositionElgibility.second_base))) 13.844567
10 Charlie Blackmon (((PositionElgibility.outfield))) 13.819956
7 Josh Donaldson (((PositionElgibility.third_base))) 13.684719
3 Kris Bryant (((PositionElgibility.third_base)), ((Position... 13.443700
15 Starling Marte (((PositionElgibility.outfield))) 12.900908

What does it take to win a category?


In [34]:
league_winners = razz.groupby('League').head(1)

In [58]:
league_winners[['R', 'HR', 'RBI', 'SB', 'AVG', 'W', 'SV', 'K', 'ERA', 'WHIP']].describe()


Out[58]:
R HR RBI SB AVG W SV K ERA WHIP
count 85.000000 85.000000 85.000000 85.000000 85.000000 85.000000 85.000000 85.000000 85.000000 85.000000
mean 1139.929412 326.341176 1092.952941 160.811765 0.273040 93.458824 138.494118 1436.235294 3.494235 1.196000
std 48.868333 23.573872 41.362194 29.112873 0.005946 9.129430 29.348734 103.537737 0.196283 0.046706
min 1011.000000 276.000000 989.000000 93.000000 0.256400 74.000000 80.000000 1172.000000 3.130000 1.090000
25% 1104.000000 310.000000 1062.000000 137.000000 0.268500 87.000000 121.000000 1373.000000 3.340000 1.170000
50% 1139.000000 328.000000 1098.000000 159.000000 0.272900 93.000000 133.000000 1436.000000 3.490000 1.190000
75% 1169.000000 344.000000 1122.000000 181.000000 0.276800 99.000000 153.000000 1485.000000 3.610000 1.230000
max 1283.000000 376.000000 1172.000000 235.000000 0.286600 118.000000 240.000000 1801.000000 3.960000 1.300000