nfldb
nfldb copied to clipboard
Two passing leaders for each team
Probably I do something wrong... but here is my problem. I try to find 2 passing leaders for each team for each season.
I have a list of all teams, so I do a loop over all teams and all years.
years=range(2009,2016)
for cur_year in years :
print cur_year
for cur_team in all_teams :
print cur_team
cur_query=nfldb.Query(db)
cur_query.game(season_year=cur_year, season_type='Regular',team=cur_team)
cur_query.player(team=cur_team)
for pp in cur_query.sort('passing_yds').limit(2).as_aggregate():
print pp.player, pp.passing_yds
print "______________"
For the moment I have at least two problems with 2015 season.
a) No data for STL; b) No data for DEN
Probably because Case Keenum play now for LA and Nick Foles for KC. The same for Denver, because Peyton Manning marked as UNK.
I could remove the line cur_query.player(team=cur_team)
,
but in this case I get not the two bests passers of the team, but the best passer of the team and his best opponent passer for this season.
Example for 2015 for NYJ I got :
NYJ Ryan Fitzpatrick (NYJ, QB) 3905 Tom Brady (NE, QB) 586
So, probably it's not an issue... but may be you could give a clue how I could solve this problem?
it might relate to this:
game.players is a list of tuples of player data. The first element is the team the player was on during the game and the second element is a Player object corresponding to that player's meta data (including the team he's currently on).
Cur_team is the team the player is currently on, not necessarily the team he was on when the game was played?