BurntSushi / nflgame

An API to retrieve and read NFL Game Center JSON data. It can work with real-time data, which can be used for fantasy football.
http://pdoc.burntsushi.net/nflgame
The Unlicense
1.27k stars 413 forks source link

Pass Completions over 30 yds #309

Open Ash-Digital opened 7 years ago

Ash-Digital commented 7 years ago

Hello,

Just getting familiar with how this works and asked my friend to ask me an obscure stat. He said "Most pass completions over 30 yds in 2007."

I'm wondering how I'd go about getting that information. Do I have to list out every week in 2007 or can I just leave it at 2007? I made an attempt below but it's missing quite a bit from there.

games = nflgame.games(2007) players = nflgame.combine(games) for p in players.passing().sort("passing_yds"): ... print p, p.passing_cmp

ochawkeye commented 6 years ago

When you group players = nflgame.combine(games) you are aggregating a players entire season stats, destroying any granularity you had in determining his long passes. What you're doing there is sorting the players that had the most completion yards in a particular season and then displaying their name along with how many total completions they had in that season.

FYI - 2007 is not included in the dataset available to nflgame.

Here is how I would attempt to do what you're trying to do. Please feel free to ask if you have any questions on this.

(58 players completed at least one pass over 30 yards in 2017)

import nflgame
from collections import defaultdict

games = nflgame.games(2017, kind='REG')
plays = nflgame.combine_plays(games).filter(passing_yds=lambda v: v > 30)

long_passers = defaultdict(int)

for play in plays:
    for player in play.players.passing():
        long_passers[player.name] += 1

for name, completions in sorted(long_passers.iteritems(), key=lambda (k,v): (v,k), reverse=True):
    print name, completions
A.Smith 28
M.Stafford 27
K.Cousins 27
B.Roethlisberger 25
...
G.Smith 1
E.Manuel 1
D.Stanton 1
C.Kessler 1