In [13]:
import nflgame
In [14]:
game = nflgame.one(2014, 2, "SEA", "CAR", kind='POST')
In [17]:
print game.players
In [18]:
print game.players.passing().filter(home=True)
In [104]:
for p in game.players.passing().filter(home=True):
print p, p.passing_cmp, p.passing_att, p.passing_yds, p.tds, p.passing_ints
In [6]:
from __future__ import division
def passer_rating(self):
l = [((self.passing_cmp / self.passing_att) - .3) * 5]
l.append(((self.passing_yds / self.passing_att) - 3) * .25)
l.append((self.tds / self.passing_att) * 20)
l.append(2.375 - (self.passing_ints / self.passing_att * 25))
m = []
for a in l:
if a < 0:
a = 0
m.append(a)
elif a > 2.375:
a = 2.375
m.append(a)
else:
m.append(a)
rating = round((sum(m) / 6) * 100, 1)
return rating
In [19]:
for p in game.players.passing():
print p, passer_rating(p)
In [119]:
russ = game.players.name("R.Wilson")
print russ, "\n", russ.formatted_stats()
In [24]:
skittles = game.players.name("M.Lynch")
print skittles, "\n", skittles.formatted_stats()
In [22]:
games = nflgame.games(2014, week=[1,2,3,4,5]) #Print for weeks 1-5 of the 2013 season - adjust as needed
for g in games:
print "{0} Won Over {1} - Week {2}".format(g.winner, g.loser, g.schedule['week'])
In [23]:
# We want the games Buffalo played in 2013
team_to_check = 'SEA'
# Create a list to store each score
game_scores_for = []
game_scores_against = []
# Get the games Buffalo played in the 2013 Regular Season
games = nflgame.games_gen(2014, home=team_to_check, away=team_to_check, kind='REG')
# Iterate through the games
for g in games:
# If Buffalo was home, add the score_home to the points for list and the score_away to the points against list
if g.home == team_to_check:
game_scores_for.append(g.score_home)
game_scores_against.append(g.score_away)
# If Buffalo was away, add the score_away to the points for list and the score_home to the points against list
else:
game_scores_for.append(g.score_away)
game_scores_against.append(g.score_home)
# Print our the sum of our values divided by the number of values. Cast to a float to get decimal points
print team_to_check, "has averaged", sum(game_scores_for)/float(len(game_scores_for)), "points scored per game in 2014"
print team_to_check, "has averaged", sum(game_scores_against)/float(len(game_scores_against)), "points against per game in 2014"
In [ ]: