In [5]:
%matplotlib inline

import pandas as pd
import matplotlib as mp
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

qb_games = pd.read_csv('qb_games.csv')
qb_games.columns.values


Out[5]:
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'], dtype=object)

In [6]:
qb_games['Fantasy Points'] = (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_fantasy = qb_games[['Name','Career Year', 'Year', 'GameCount', 'Career Games', 'Date', 'Pass Att', 'Pass Yds', 'Pass TD', 'Pass Int', 'Pass Rate', 'Rush Att', 'Rush Yds', 'Rush TD', 'Fantasy Points']]

qb_fantasy.head(10)


Out[6]:
Name Career Year Year GameCount Career Games Date Pass Att Pass Yds Pass TD Pass Int Pass Rate Rush Att Rush Yds Rush TD Fantasy Points
0 feeley, aj 1 2001 1 1 01/06/02 14 143 2 1 114.0 0 0 0 15.72
1 feeley, aj 2 2002 1 2 11/25/02 3 17 1 0 129.9 2 -3 0 6.38
2 feeley, aj 2 2002 2 3 12/01/02 30 181 0 0 66.1 2 3 0 7.54
3 feeley, aj 2 2002 3 4 12/08/02 35 190 2 1 81.8 3 0 0 17.60
4 feeley, aj 2 2002 4 5 12/15/02 28 220 2 1 91.4 2 5 0 19.30
5 feeley, aj 2 2002 5 6 12/21/02 33 253 1 2 66.9 2 2 0 12.32
6 feeley, aj 2 2002 6 7 12/28/02 25 150 0 1 53.8 1 -1 0 3.90
7 feeley, aj 4 2004 2 8 09/19/04 39 218 1 2 57.4 0 0 0 10.72
8 feeley, aj 4 2004 3 9 09/26/04 27 137 0 2 32.5 0 0 0 1.48
9 feeley, aj 4 2004 4 10 10/10/04 2 6 0 0 56.3 0 0 0 0.24

In [7]:
qb_2016 = qb_games.loc[(qb_games.Year == 2016) & (qb_games.GameCount < 19)]
print(len(qb_2016))
qb_2016_sum = qb_2016.groupby(['Name', 'Year'], as_index=False).sum()[['Name', 'Pass Yds', 'Pass TD', 'Pass Int', 'Rush Yds', 'Rush TD', 'Fantasy Points']]
qb_2016_sum = qb_2016_sum.sort_values(['Fantasy Points'], ascending=False)


311
Out[7]:
Name Pass Yds Pass TD Pass Int Rush Yds Rush TD Fantasy Points
22 rodgers, aaron 5145 46 8 0 0 465.80
25 ryan, matt 5282 41 7 0 0 443.28
3 brees, drew 5208 37 15 20 2 414.32
29 stafford, matthew 4532 24 10 222 2 339.48
21 rivers, philip 4386 33 21 0 0 331.44
2 brady, tom 3841 30 4 0 0 325.64
23 roethlisberger, ben 4240 31 16 0 0 323.60
7 dalton, andy 4206 18 8 184 4 302.64
16 manning, eli 4326 27 17 2 0 301.24
20 palmer, carson 4233 26 14 0 0 297.32
19 newton, cam 3509 19 14 359 5 292.26
10 flacco, joe 4317 20 15 58 2 280.48
1 bradford, sam 3877 20 5 53 0 270.38
28 smith, alex 3674 16 9 143 5 269.26
15 kaepernick, colin 2241 16 4 468 2 236.44
30 taylor, tyrod 3023 17 6 0 0 210.92
9 fitzpatrick, ryan 2710 12 17 0 0 146.40
14 hoyer, brian 1445 6 0 -2 0 93.60
18 moore, matt 1010 9 4 0 0 86.40
11 gabbert, blaine 925 5 6 173 2 84.30
17 mccown, josh 1100 6 6 0 0 68.00
6 cutler, jay 1059 4 5 0 0 56.36
0 anderson, derek 453 2 5 0 0 20.12
4 cassel, matt 284 2 2 0 0 19.36
31 whitehurst, charlie 182 1 1 0 0 11.28
13 hill, shaun 242 0 0 0 0 9.68
24 romo, tony 29 1 0 0 0 7.16
27 schaub, matt 16 0 0 0 0 0.64
8 daniel, chase 16 0 0 0 0 0.64
12 henne, chad 0 0 0 0 0 0.00
5 clemens, kellen 0 0 0 0 0 0.00
26 sanchez, mark 93 0 2 -2 0 -0.48

In [48]:
qb_2016 = qb_games.loc[(qb_games.Year == 2016) & (qb_games.GameCount < 18)]
print(len(qb_2016))
rodgers = qb_2016.loc[qb_2016.Name == 'rodgers, aaron']
rodgers.head(16)


310
Out[48]:
Name Year Career Year GameCount Career Games Date Team Opp Result Pass Att ... Pass Lg Pass Sack Pass Rate Rush Att Rush Yds Rush Avg Rush Lg Rush TD Rush FD Fantasy Points
165 rodgers, aaron 2016 12 1 140 09/11/16 GB @ Jax W, 27-23 34 ... 32 1/0 95.1 0 0 0.0 0 0 0 19.96
166 rodgers, aaron 2016 12 2 141 09/18/16 GB @ Min L, 17-14 36 ... 39 5/33 70.7 0 0 0.0 0 0 0 12.52
167 rodgers, aaron 2016 12 3 142 09/25/16 GB Det W, 34-27 24 ... 49 2/4 129.3 0 0 0.0 0 0 0 32.20
168 rodgers, aaron 2016 12 4 143 10/09/16 GB NYG W, 23-16 45 ... 29t 0/0 65.0 0 0 0.0 0 0 0 18.36
169 rodgers, aaron 2016 12 5 144 10/16/16 GB Dal L, 30-16 42 ... 25 1/0 90.8 0 0 0.0 0 0 0 15.76
170 rodgers, aaron 2016 12 6 145 10/20/16 GB Chi W, 26-10 56 ... 25 2/23 102.2 0 0 0.0 0 0 0 31.04
171 rodgers, aaron 2016 12 7 146 10/30/16 GB @ Atl L, 33-32 38 ... 58 3/23 125.5 0 0 0.0 0 0 0 33.84
172 rodgers, aaron 2016 12 8 147 11/06/16 GB Ind L, 31-26 43 ... 40 3/8 94.8 0 0 0.0 0 0 0 27.88
173 rodgers, aaron 2016 12 9 148 11/13/16 GB @ Ten L, 47-25 51 ... 46 5/46 79.8 0 0 0.0 0 0 0 22.84
174 rodgers, aaron 2016 12 10 149 11/20/16 GB @ Was L, 42-24 41 ... 47 2/20 115.0 0 0 0.0 0 0 0 32.04
175 rodgers, aaron 2016 12 11 150 11/28/16 GB @ Phi W, 27-13 39 ... 50 0/0 116.7 0 0 0.0 0 0 0 24.52
176 rodgers, aaron 2016 12 12 151 12/04/16 GB Hou W, 21-13 30 ... 32t 1/9 108.9 0 0 0.0 0 0 0 20.36
177 rodgers, aaron 2016 12 13 152 12/11/16 GB Sea W, 38-10 23 ... 66t 1/9 150.8 0 0 0.0 0 0 0 27.84
178 rodgers, aaron 2016 12 14 153 12/18/16 GB @ Chi W, 30-27 31 ... 60 4/27 87.0 0 0 0.0 0 0 0 10.08
179 rodgers, aaron 2016 12 15 154 12/24/16 GB Min W, 38-25 38 ... 48 4/39 136.6 0 0 0.0 0 0 0 37.88
180 rodgers, aaron 2016 12 16 155 01/01/17 GB @ Det W, 31-24 39 ... 39 1/5 126.0 0 0 0.0 0 0 0 36.00

16 rows × 26 columns


In [8]:
qb_2016_sum.to_csv('qb_sanity.csv')
print('Done!')


Done!