Skip to content

Instantly share code, notes, and snippets.

import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
p, y, w = nfldb.current(db)
q.game(season_type=p, season_year=y, week=w)
print p, y, w
for pp in q.sort('passing_yds').limit(10).as_aggregate():
print pp.player, pp.passing_yds
import nfldb
from collections import defaultdict
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2015, week=7)
results = {team[0]: {} for team in nfldb.team.teams}
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2015)
interceptions = {team[0]: 0 for team in nfldb.team.teams}
fumble_recoveries = {team[0]: 0 for team in nfldb.team.teams}
turnovers = {team[0]: 0 for team in nfldb.team.teams}
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
year, week = 2015, 7
q.game(season_year=year, week=week)
q.play(fourth_down_att=1)
attempts = 0
att_converted = 0
att_failed = 0
import nflgame
year, week = 2015, 7
games = nflgame.games(year=year, week=week)
plays = nflgame.combine_plays(games).filter(fourth_down_att=True)
attempts = 0
att_converted = 0
att_failed = 0
for play in plays:
@ochawkeye
ochawkeye / chp.py
Last active October 20, 2015 18:15
import nfldb
NYGmisc = {}
db = nfldb.connect()
qNYG = nfldb.Query(db)
for gp in qNYG.play_player(team='NYG').player(position='TE').as_aggregate():
# NYGmisc[gp.player] = gp <-- if you do like this, the values are class 'nfldb.query.AggPP'
NYGmisc[gp.player] = {field: getattr(gp, field) for field in gp.fields} # but if you do like this they are type 'dict'
for x in NYGmisc:
print type(x), type(NYGmisc[x])
@ochawkeye
ochawkeye / cooper_nfldb.py
Created September 23, 2015 17:01
Amari Cooper in NFLDB
import nfldb
name = 'Amari Cooper'
team = 'OAK'
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2015, season_type='Regular')
q.player(full_name=name, team=team)
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2012, season_type='Regular')
q.player(full_name='Julian Edelman').play_player(offense_tds=1)
for g in q.as_games():
print g
print '-'*79
@ochawkeye
ochawkeye / simple nfldb query
Created August 31, 2015 20:42
simple nfldb query
import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2015, season_type='Preseason')
for game in q.as_games():
print game
@ochawkeye
ochawkeye / funny_gsis.py
Last active August 29, 2015 14:06
Where are those names coming from?
import nflgame
games = nflgame.games(2014, week=1, kind='REG')
players = nflgame.combine_game_stats(games)
meta = nflgame.players
for x in players:
if str(x) == 'M.Ryan':
print x.playerid, meta[x.playerid], meta[x.playerid].gsis_name, x
if '.' not in str(x):