Stat Category Point Value
Passing Yards 1 point for every 25 yards
Rushing Yards 1 point for every 10 yards
Rushing TDs 6 points
Receiving Yards 1 point for every 10 yards
Receiving TDs 6 points
Interceptions -2 points

Set environment


In [1]:
%matplotlib inline

import pandas as pd
import matplotlib as mp
import numpy as np
import seaborn as sns

Read in footballdb 2016 summary stats for QBs, RBs, and WRs


In [2]:
football_db = pd.read_csv('FootballDB2016YearlyStats.csv')
football_db.columns.values


Out[2]:
array(['Player', 'Pos', 'FantasyPts', 'Att', 'Cmp', 'Yds', 'PassTD', 'Int',
       '2Pt', 'RushAtt', 'RushYds', 'RushTDs', '2Pt.1', 'Rec', 'RecYds',
       'RecTD', '2Pt.2', 'FL', 'TD', 'CalcFantasyPoints'], dtype=object)

Get the Variances between the provided Fantasy Score and the Calculated score


In [3]:
football_db['FantasyVariance'] = (football_db.FantasyPts / football_db.CalcFantasyPoints)
# Correct any divide by 0 errors
football_db['FantasyVariance'].replace([np.inf, -np.inf], 0)    
print('Done')


Done

In [4]:
football_db.to_csv('Checkdata.csv')

Calculate the mean, the median and the standard variation


In [5]:
fantasy_mean = football_db.FantasyVariance.mean()
fantasy_median = football_db.FantasyVariance.median()
print('The mean for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_mean))
print('The median for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_median))


The mean for the variance between provided score and the calculated score is: 0.9524.
The median for the variance between provided score and the calculated score is: 0.9430.

In [6]:
#

In [7]:
x = football_db['FantasyVariance']
sns.set_context('poster')
sns.set_style("ticks")

g=sns.distplot(x,
            kde_kws={"color":"g","lw":4,"label":"KDE Estim","alpha":0.5},
            hist_kws={"color":"r","alpha":0.3,"label":"Freq"})


# remove the top and right line in graph
sns.despine()

# Set the size of the graph from here
g.figure.set_size_inches(12,7)
# Set the Title of the graph from here
g.axes.set_title('Provided and Calculated Fantasy Point Variance Distribution', fontsize=34,color="b",alpha=0.3)
# Set the xlabel of the graph from here
g.set_xlabel("Variance",size = 67,color="g",alpha=0.5)
# Set the ylabel of the graph from here
g.set_ylabel("Density",size = 67,color="r",alpha=0.5)
# Set the ticklabel size and color of the graph from here
g.tick_params(labelsize=14,labelcolor="black")


/Users/jph/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j

In [8]:
qb = football_db.loc[football_db.Pos == 'QB']
x = qb['FantasyVariance']
fantasy_mean = x.mean()
fantasy_median = x.median()
fantasy_std = np.std(x)
print('The mean for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_mean))
print('The median for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_median))
print('The standard deviation for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_std))


g=sns.distplot(x)


The mean for the variance between provided score and the calculated score is: 0.9751.
The median for the variance between provided score and the calculated score is: 0.9785.
The standard deviation for the variance between provided score and the calculated score is: 0.1249.
/Users/jph/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j

In [28]:
rb = football_db.loc[football_db.Pos == 'RB']
print(type(rb))
x = rb['FantasyVariance']
fantasy_mean = x.mean()
fantasy_median = x.median()

fantasy_std = np.std(x)
print('The mean for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_mean))
print('The median for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_median))
print('The standard deviation for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_std))


g=sns.distplot(x)


<class 'pandas.core.frame.DataFrame'>
The mean for the variance between provided score and the calculated score is: 0.9178.
The median for the variance between provided score and the calculated score is: 0.8781.
The standard deviation for the variance between provided score and the calculated score is: 0.2956.
/Users/jph/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j

In [10]:
wr = football_db.loc[football_db.Pos == 'WR']
x = wr['FantasyVariance']
fantasy_mean = x.mean()
fantasy_median = x.median()
fantasy_std = np.std(x)
print('The mean for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_mean))
print('The median for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_median))
print('The standard deviation for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_std))



g=sns.distplot(x,
            kde_kws={"color":"g","lw":4,"label":"KDE Estim","alpha":0.5},
            hist_kws={"color":"r","alpha":0.3,"label":"Freq"})


The mean for the variance between provided score and the calculated score is: 0.9726.
The median for the variance between provided score and the calculated score is: 0.9329.
The standard deviation for the variance between provided score and the calculated score is: 0.1957.
/Users/jph/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j

Only has to be run once.

If 'Name' exists in Checkdata.csv, this step can be skipped. This will format the 'Player' data column scraped from the footballdb.com website, which has this format: "Aaron Rodgers, GB", and writes out a 'Name' data column that will match the game by game Name field and look like this: "rodgers, aaron"


In [11]:
name = []
for index, row in football_db.iterrows():
    full_name = row.Player
    split_name = full_name.split()
    first_name = split_name[0]
    last_name = split_name[1]
    name.append(last_name.lower() + ' ' + first_name.lower())
    
football_db['Name'] = name
football_db.to_csv('Checkdata.csv')
print('Done!')


Done!

In [12]:
qb_games = pd.read_csv('qb_games.csv')
qb_games['FantasyPoints'] = (qb_games['Pass Yds']/25) + (6 * qb_games['Pass TD']) - (2 * qb_games['Pass Int']) + (qb_games['Rush Yds'] /10) + (6 * qb_games['Rush TD'])
qb_games.columns.values


Out[12]:
array(['Name', 'Year', 'Career Year', 'GameCount', 'Career Games', 'Date',
       'Team', 'Opp', 'Result', 'Pass Att', 'Pass Cmp', 'Pass Pct',
       'Pass Yds', 'Pass YPA', 'Pass TD', 'Pass Int', 'Pass Lg',
       'Pass Sack', 'Pass Rate', 'Rush Att', 'Rush Yds', 'Rush Avg',
       'Rush Lg', 'Rush TD', 'Rush FD', 'FantasyPoints'], dtype=object)

In [13]:
footballdb_qb = football_db.loc[football_db.Pos == 'QB']
footballdb_qb.head(10)


Out[13]:
Player Pos FantasyPts Att Cmp Yds PassTD Int 2Pt RushAtt ... 2Pt.1 Rec RecYds RecTD 2Pt.2 FL TD CalcFantasyPoints FantasyVariance Name
0 Aaron Rodgers, GB QB 449 610 401 4,428 40 7 1 67 ... 1 0 0 0 0 4 0 441.88 1.016113 rodgers, aaron
1 Matt Ryan, Atl QB 412 534 373 4,944 38 7 1 35 ... 1 0 0 0 0 2 0 416.44 0.989338 ryan, matt
2 Drew Brees, NO QB 401 673 471 5,208 37 15 0 23 ... 0 0 0 0 0 4 0 413.12 0.970662 brees, drew
3 Andrew Luck, Ind QB 364 545 346 4,240 31 13 2 64 ... 0 0 0 0 0 5 0 355.24 1.024659 luck, andrew
4 Kirk Cousins, Was QB 343 606 406 4,917 25 12 0 34 ... 0 0 0 0 0 3 0 350.52 0.978546 cousins, kirk
5 Philip Rivers, SD QB 321 578 349 4,386 33 21 0 14 ... 0 0 0 0 0 5 0 332.84 0.964427 rivers, philip
6 Dak Prescott, Dal QB 321 459 311 3,667 23 4 0 57 ... 0 0 0 0 0 4 0 323.96 0.990863 prescott, dak
7 Matthew Stafford, Det QB 317 594 388 4,327 24 10 1 37 ... 0 0 0 0 0 2 0 317.36 0.998866 stafford, matthew
8 Derek Carr, Oak QB 316 560 357 3,937 28 6 5 39 ... 0 0 0 0 0 3 0 317.08 0.996594 carr, derek
9 Blake Bortles, Jax QB 311 625 368 3,905 23 16 1 58 ... 1 1 20 1 0 6 0 300.56 1.034735 bortles, blake

10 rows × 22 columns


In [14]:
qb_games2016 = qb_games.loc[qb_games.Year == 2016]

qb_games2016 = qb_games2016[['Name', 'FantasyPoints']]
football_db_qb = footballdb_qb[['Name', 'CalcFantasyPoints']]
qb_games2016_sum = qb_games2016.groupby(['Name'], as_index=False).sum()

In [15]:
football_db_qb.head(10)


Out[15]:
Name CalcFantasyPoints
0 rodgers, aaron 441.88
1 ryan, matt 416.44
2 brees, drew 413.12
3 luck, andrew 355.24
4 cousins, kirk 350.52
5 rivers, philip 332.84
6 prescott, dak 323.96
7 stafford, matthew 317.36
8 carr, derek 317.08
9 bortles, blake 300.56

In [16]:
qb_merged = qb_games2016_sum.merge(football_db_qb, on='Name')
print(len(qb_games2016_sum))
print(len(qb_merged))


32
27

In [17]:
qb_var = qb_merged.FantasyPoints / qb_merged.CalcFantasyPoints

fantasy_mean = qb_var.mean()
fantasy_median = qb_var.median()
fantasy_std = np.std(qb_var)
print('The mean for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_mean))
print('The median for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_median))
print('The standard deviation for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_std))



g=sns.distplot(qb_var,
            kde_kws={"color":"g","lw":4,"label":"KDE Estim","alpha":0.5},
            hist_kws={"color":"r","alpha":0.3,"label":"Freq"})


The mean for the variance between provided score and the calculated score is: 1.0274.
The median for the variance between provided score and the calculated score is: 1.0114.
The standard deviation for the variance between provided score and the calculated score is: 0.0750.
/Users/jph/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j

In [18]:
rb_games = pd.read_csv('rb_games.csv')
rb_games['FantasyPoints'] = ((rb_games['Rush Yds'] + rb_games['Rec Yds']) / 10) + ((rb_games['Rush TD'] + rb_games['Rec TD']) *6)

rb_games2016 = rb_games.loc[rb_games.Year == 2016]

footballdb_rb = football_db.loc[football_db.Pos == 'RB']
print(len(footballdb_rb))

rb_games2016 = rb_games2016[['Name', 'FantasyPoints']]
football_db_rb = footballdb_rb[['Name', 'CalcFantasyPoints']]
rb_games2016_sum = rb_games2016.groupby(['Name'], as_index=False).sum()
rb_games2016_sum.head(32)


99
Out[18]:
Name FantasyPoints
0 blount, legarrette 227.2
1 bush, reggie 14.7
2 charles, jamaal 10.0
3 felton, jerome 7.0
4 forsett, justin 35.1
5 forte, matt 123.3
6 foster, arian 5.5
7 gore, frank 178.2
8 harris, dujuan 31.3
9 hightower, tim 104.8
10 ingram, mark 196.2
11 ivory, chris 61.9
12 johnson, chris 15.5
13 jones, taiwan 3.5
14 kuhn, john 40.7
15 lewis, dion 56.1
16 mathews, ryan 131.6
17 mccluster, dexter 3.8
18 mccoy, lesean 204.7
19 mcfadden, darren 10.4
20 murray, demarco 238.4
21 peerman, cedric 1.5
22 peterson, adrian 8.0
23 powell, bilal 141.0
24 ridley, stevan 0.7
25 rodgers, jacquizz 77.8
26 sherman, anthony 1.4
27 spiller, cj 12.8
28 sproles, darren 110.5
29 starks, james 14.5
30 stewart, jonathan 136.4
31 tolbert, mike 24.6

In [19]:
rb_merged = rb_games2016_sum.merge(football_db_rb, on='Name')
print(len(rb_games2016_sum))
print(len(rb_merged))


35
24

In [20]:
rb_var = rb_merged.FantasyPoints / rb_merged.CalcFantasyPoints

fantasy_mean = rb_var.mean()
fantasy_median = rb_var.median()
fantasy_std = np.std(rb_var)
print('The mean for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_mean))
print('The median for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_median))
print('The standard deviation for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_std))



g=sns.distplot(rb_var,
            kde_kws={"color":"g","lw":4,"label":"KDE Estim","alpha":0.5},
            hist_kws={"color":"r","alpha":0.3,"label":"Freq"})


The mean for the variance between provided score and the calculated score is: 0.9450.
The median for the variance between provided score and the calculated score is: 0.9136.
The standard deviation for the variance between provided score and the calculated score is: 0.3279.
/Users/jph/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j

In [21]:
wr_games = pd.read_csv('wr_games.csv')
wr_games['FantasyPoints'] = ((wr_games['Rush Yds'] + wr_games['Rec Yds']) / 10) + ((wr_games['Rush TD'] + wr_games['Rec TD']) *6)

wr_games2016 = wr_games.loc[wr_games.Year == 2016]

footballdb_wr = football_db.loc[football_db.Pos == 'WR']
print(len(footballdb_wr))

wr_games2016 = wr_games2016[['Name', 'FantasyPoints']]
footballdb_wr = footballdb_wr[['Name', 'CalcFantasyPoints']]
wr_games2016_sum = wr_games2016.groupby(['Name'], as_index=False).sum()
print(len(wr_games2016_sum))
wr_games2016_sum.head(32)


100
184
Out[21]:
Name FantasyPoints
0 abbrederis, jared 0.8
1 adams, davante 197.8
2 agholor, nelson 48.5
3 aiken, kamar 38.8
4 alford, mario 0.0
5 allen, keenan 6.3
6 allison, geronimo 37.6
7 amendola, danny 48.3
8 austin, tavon 68.9
9 baldwin, doug 185.3
10 beasley, cole 117.8
11 beckham, odell 199.5
12 bellamy, joshua 34.2
13 benjamin, kelvin 136.1
14 benjamin, travis 91.7
15 benn, arrelious 17.6
16 bersin, brenton 1.7
17 boldin, anquan 108.8
18 boyd, tyler 66.5
19 bray, quan 3.6
20 britt, kenny 130.2
21 brown, antonio 235.6
22 brown, jaron 24.7
23 brown, john 63.7
24 brown, philly 33.6
25 bryant, dez 152.9
26 burbridge, aaron 8.8
27 burse, isaiah 0.0
28 butler, brice 39.9
29 butler, jeremy 1.1
30 campanaro, michael 0.0
31 carroo, leonte 8.9

In [22]:
wr_merged = wr_games2016_sum.merge(footballdb_wr, on='Name')
print(len(wr_games2016_sum))
print(len(wr_merged))


184
91

In [23]:
wr_var = wr_merged.FantasyPoints / wr_merged.CalcFantasyPoints

fantasy_mean = wr_var.mean()
fantasy_median = wr_var.median()
fantasy_std = np.std(wr_var)
print('The mean for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_mean))
print('The median for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_median))
print('The standard deviation for the variance between provided score and the calculated score is: {0:.4f}.'.format(fantasy_std))



g=sns.distplot(wr_var,
            kde_kws={"color":"g","lw":4,"label":"KDE Estim","alpha":0.5},
            hist_kws={"color":"r","alpha":0.3,"label":"Freq"})


The mean for the variance between provided score and the calculated score is: 1.0651.
The median for the variance between provided score and the calculated score is: 1.0243.
The standard deviation for the variance between provided score and the calculated score is: 0.2779.
/Users/jph/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j

In [ ]:


In [235]:
qb_by_year  = qb_games.groupby(['Name', 'Year', 'Career Year'], as_index=False)[['FantasyPoints']].sum()
qb_by_year['FantasyMean'] = qb_by_year.FantasyPoints / 16
qb2013 = qb_by_year.loc[qb_by_year.Year == 2013].sort_values(['FantasyPoints'], ascending=False)
qb2013 = qb2013.head(20)
qb2013_fp_mean = qb2013.FantasyPoints.mean()
qb2013_fm_mean = qb2013.FantasyMean.mean()
print('The 2013 fantasy score mean is: %d' %(qb2013_fp_mean))
print('The 2013 fantasy mean is: %d' %(qb2013_fm_mean))


The 2013 fantasy score mean is: 286
The 2013 fantasy mean is: 17

In [236]:
qb2014 = qb_by_year.loc[qb_by_year.Year == 2014].sort_values(['FantasyPoints'], ascending=False)
qb2014 = qb2014.head(20)
qb2014_fp_mean = qb2014.FantasyPoints.mean()
qb2014_fm_mean = qb2014.FantasyMean.mean()
print('The 2014 fantasy score mean is: %d' %(qb2014_fp_mean))
print('The 2014 fantasy mean is: %d' %(qb2014_fm_mean))


The 2014 fantasy score mean is: 301
The 2014 fantasy mean is: 18

In [229]:
qb2015 = qb_by_year.loc[qb_by_year.Year == 2015].sort_values(['FantasyPoints'], ascending=False)
qb2015_fp_mean = qb2015.FantasyPoints.mean()
qb2015_fm_mean = qb2015.FantasyMean.mean()
print('The 2015 fantasy score mean is: %d' %(qb2015_fp_mean))
print('The 2015 fantasy mean is: %d' %(qb2015_fm_mean))
qb2015.head(20)


The 2015 fantasy score mean is: 175
The 2015 fantasy mean is: 10
Out[229]:
Name Year FantasyPoints FantasyMean
397 newton, cam 2015 533.02 33.31375
56 brady, tom 2015 462.48 28.90500
429 palmer, carson 2015 418.60 26.16250
466 rodgers, aaron 2015 406.08 25.38000
73 brees, drew 2015 364.80 22.80000
339 manning, eli 2015 359.28 22.45500
542 stafford, matthew 2015 358.38 22.39875
176 fitzpatrick, ryan 2015 351.20 21.95000
534 smith, alex 2015 341.78 21.36125
454 rivers, philip 2015 339.68 21.23000
548 taylor, tyrod 2015 310.20 19.38750
152 dalton, andy 2015 298.20 18.63750
500 ryan, matt 2015 283.94 17.74625
479 roethlisberger, ben 2015 283.14 17.69625
146 cutler, jay 2015 276.46 17.27875
39 bradford, sam 2015 238.90 14.93125
268 hoyer, brian 2015 201.68 12.60500
185 flacco, joe 2015 171.64 10.72750
352 mccown, josh 2015 164.16 10.26000
204 gabbert, blaine 2015 151.74 9.48375

In [234]:
qb2016 = qb_by_year.loc[qb_by_year.Year == 2016].sort_values(['FantasyPoints'], ascending=False)
qb2016_fp_mean = qb2016.FantasyPoints.mean()
qb2016_fm_mean = qb2016.FantasyMean.mean()
print('The 2016 fantasy score mean is: %d' %(qb2016_fp_mean))
print('The 2016 fantasy mean is: %d' %(qb2016_fm_mean))
qb2016.head(20)


The 2016 fantasy score mean is: 178
The 2016 fantasy mean is: 11
Out[234]:
Name Year Career Year FantasyPoints FantasyMean
467 rodgers, aaron 2016 12 465.80 29.11250
501 ryan, matt 2016 9 443.28 27.70500
74 brees, drew 2016 16 414.32 25.89500
543 stafford, matthew 2016 8 339.48 21.21750
455 rivers, philip 2016 13 331.44 20.71500
57 brady, tom 2016 17 325.64 20.35250
480 roethlisberger, ben 2016 13 323.60 20.22500
153 dalton, andy 2016 6 302.64 18.91500
340 manning, eli 2016 13 301.24 18.82750
430 palmer, carson 2016 13 297.32 18.58250
398 newton, cam 2016 6 292.26 18.26625
186 flacco, joe 2016 9 280.48 17.53000
40 bradford, sam 2016 6 270.38 16.89875
535 smith, alex 2016 11 269.26 16.82875
289 kaepernick, colin 2016 6 236.44 14.77750
549 taylor, tyrod 2016 6 210.92 13.18250
177 fitzpatrick, ryan 2016 12 146.40 9.15000
269 hoyer, brian 2016 8 93.60 5.85000
392 moore, matt 2016 10 86.40 5.40000
205 gabbert, blaine 2016 6 84.30 5.26875

In [177]:
sns.set_context("notebook", font_scale=1.1)
sns.set_style("ticks")


sns.lmplot(y='Pass Att', x='Career Year', data=qb_by_year)


Out[177]:
<seaborn.axisgrid.FacetGrid at 0x11dfe9160>

In [ ]:


In [176]:
sns.set_context("notebook", font_scale=1.1)
sns.set_style("ticks")


sns.lmplot(y='Pass Rate', x='Career Year', data=qb_by_year)


Out[176]:
<seaborn.axisgrid.FacetGrid at 0x11dae9048>

In [172]:
sns.set_context("notebook", font_scale=1.1)
sns.set_style("ticks")


sns.lmplot(y='FantasyPoints', x='Career Year', data=qb_by_year)


Out[172]:
<seaborn.axisgrid.FacetGrid at 0x11dbeb898>

In [178]:
qb_min_passes_by_year = qb_by_year.loc[qb_by_year['Pass Att'] > 20]

sns.set_context("notebook", font_scale=1.1)
sns.set_style("ticks")


sns.lmplot(y='FantasyPoints', x='Career Year', data=qb_min_passes_by_year)


Out[178]:
<seaborn.axisgrid.FacetGrid at 0x11ea6a828>

In [179]:
qb_min_rate_by_year = qb_by_year.loc[qb_by_year['Pass Rate'] > 55]

sns.set_context("notebook", font_scale=1.1)
sns.set_style("ticks")


sns.lmplot(y='FantasyPoints', x='Career Year', data=qb_min_passes_by_year)


Out[179]:
<seaborn.axisgrid.FacetGrid at 0x11eba38d0>

In [ ]:
qb_min_comb_by_year = qb_by_year.loc[(qb_by_year['Pass Rate'] > 55) & (qb_by_year['Pass Att'] > 20) & (qb_by_year['FantasyPoints'] > 20)]

In [183]:
qb_min_comb_by_year = qb_by_year.loc[(qb_by_year['Pass Rate'] > 55) & (qb_by_year['Pass Att'] > 20) & (qb_by_year['FantasyPoints'] > 20)]

sns.set_context("notebook", font_scale=1.1)
sns.set_style("ticks")


sns.lmplot(y='FantasyPoints', x='Career Year', data=qb_min_comb_by_year)


Out[183]:
<seaborn.axisgrid.FacetGrid at 0x11f111828>

Find the lowest Fantasy Football Scores for a QB

And assign the 20 worst scores to the qb_lowest dataframe


In [164]:
qb_Fantasy = qb_games.sort_values(['FantasyPoints'], ascending=True)
qb_lowest = qb_Fantasy[['Name', 'Year', 'Career Year', 'Pass Att', 'Pass Yds', 'Pass TD', 'Pass Int', 'Rush Yds', 'Rush TD', 'FantasyPoints']].head(20)

Merge the names of the QB's with the lowest Fantasy Score of all time back into the larger dataframe to get their career stats


In [170]:
qb_lowest = qb_Fantasy.head(20)[['Name', 'Career Year']]
# Merge on Name with the qb_games dataframe
qb_low_career = qb_games.merge(qb_lowest, on='Name')
print('The number of quarterbacks who generated the 20 worst scores are: %d'%(len(qb_low_career.Name.unique())))
qb_low_career.Name.unique()


The number of quarterbacks who generated the 20 worst scores are: 16
Out[170]:
array(['smith, alex', 'gradkowski, bruce', 'batch, charlie',
       'kaepernick, colin', 'anderson, derek', 'manning, eli',
       'skelton, john', 'kitna, jon', 'boller, kyle', 'orton, kyle',
       'mccown, luke', 'sanchez, mark', 'cassel, matt', 'grossman, rex',
       'fitzpatrick, ryan', 'brady, tom'], dtype=object)

Create a Scatter plot showing the career performances for the QB's who had the 20 worst Fantasy Football point games


In [77]:
sns.set_context("notebook", font_scale=1.1)
sns.set_style("ticks")


sns.lmplot(y='FantasyPoints', x='Career Year_x', data=qb_low_career)


Out[77]:
<seaborn.axisgrid.FacetGrid at 0x1180caa58>

Group these players by name and by career year and create a Scatter Plot


In [160]:
qb_career = qb_low_career.groupby(['Name', 'Career Year_x'], as_index=False).mean()
print(len(qb_career.Name.unique()))
sns.lmplot(y='FantasyPoints', x='Career Year_x', data=qb_career)


16
Out[160]:
<seaborn.axisgrid.FacetGrid at 0x11c7b62e8>

In [163]:
qb_Fantasy = qb_games.sort_values(['FantasyPoints'], ascending=False)
qb_top_games = qb_Fantasy[['Name', 'Year', 'Career Year', 'Pass Att', 'Pass Yds', 'Pass TD', 'Pass Int', 'Rush Yds', 'Rush TD', 'FantasyPoints']].head(20)

In [43]:
qb_pass_att = qb_games.loc[(qb_games['Pass Att'] > 20) & (qb_games['Pass Rate'] > 90) & (qb_games['FantasyPoints'] > 20)]
print(type(qb_pass_att))
sns.lmplot(x='Career Year', y='FantasyPoints', data=qb_pass_att)


<class 'pandas.core.frame.DataFrame'>
Out[43]:
<seaborn.axisgrid.FacetGrid at 0x116eea198>

In [ ]:
sns.lmplot(x='Rush Att', y='FantasyPoints', data=rb_games)

In [ ]:
sns.lmplot(x='Career Year', y='FantasyPoints', data=wr_games)