Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (42 sloc) 1.74 KB
import pandas as pd
import matplotlib.pyplot as plt
import numpy
url = 'http://www.espn.com/blog/nflnation/post/_/id/225804/aaron-rodgers-could-get-some-help-from-referee-jeff-triplette'
df = pd.read_html(url)[0]
Penalties = (
df.rename(columns={
'Referee': 'Crew',
'Def. offside': 'DefOffside',
'Encroach.': 'Encroach',
'False start': 'FalseStart',
'Neutral zone': 'NeutralZone',
})
.drop(["Total"], axis=1)
)
Offensive = Penalties[['FalseStart']]
Deffensive = Penalties['DefOffside'] + Penalties['Encroach'] + Penalties['NeutralZone']
N = len(Penalties)
x, y = Offensive, Deffensive
xd = x["FalseStart"].describe()
xMax, xMin, xMean, xStd = xd[7], xd[3], xd[1], xd[2]
yd = y.describe()
yMax, yMin, yMean, yStd = yd[7], yd[3], yd[1], yd[2]
StdDevs = 2
plt.scatter(x,y)
plt.xlabel('Offensive Penalties')
plt.ylabel('Deffensive Penalties')
plt.title('Referee Crew Penalty Calls')
plt.axvline(x=xMean, ls="--")
graph_expansion = 15
borders = [(xMean-StdDevs*xstd)-graph_expansion, (xMean+StdDevs*xstd)+graph_expansion, (yMean-StdDevs*ystd)-graph_expansion, (yMean+StdDevs*ystd)+graph_expansion]
box = [(xMean-StdDevs*xstd), (xMean+StdDevs*xstd), (yMean-StdDevs*ystd), (yMean+StdDevs*ystd)]
plt.axhspan(ymin=box[2], ymax=box[3], xmin=(box[0] - borders[0]) / (borders[1] - borders[0]), xmax=(box[1] - borders[0]) / (borders[1] - borders[0]), facecolor='0.5', alpha= 0.25)
plt.axis(borders)
plt.axhline(y=yMean, ls="--")
for i, crew in enumerate(Penalties.Crew):
xx, yy = x.ix[i], y.ix[i]
xcond = (-StdDevs*xstd <= (xx['FalseStart'] - xMean) <= StdDevs*xstd)
ycond = (-StdDevs*ystd <= (yy - yMean) <= StdDevs*ystd)
if not xcond or not ycond:
plt.annotate(crew, (xx['FalseStart'], yy))
plt.show()