Get team player was on during the game, not current team
See original GitHub issueI am trying to create a master table of every player (besides kickers) and each of their stats for each week. I want the ‘Team’ column in the table to show the team they were on for that game, not the team that they are currently on; but, I am not sure how to do this.
import nfldb
import pandas as pd
from pandas import DataFrame as df
db = nfldb.connect()
playerList = []
bigList = []
def Get_Yds_Per(yds,att):
if att != 0:
return yds / att
elif att == 0:
return 0
q = nfldb.Query(db)
q.game(season_year=2015,season_type='Regular')
q.player(position__ne='K')
for g in q.as_players():
playerList.append([str(g.full_name),str(g.team),str(g.position)])
for i in range(1,18):
for p in playerList:
q = nfldb.Query(db)
q.game(season_year=2015,season_type='Regular',week=i)
q.player(full_name=p[0])
for a in q.as_aggregate():
bigList.append([p[0],p[1],p[2],i,a.passing_cmp,a.passing_att,a.passing_yds,
Get_Yds_Per(a.passing_cmp_air_yds,a.passing_att),a.passing_int,
a.passing_tds,a.passing_sk,a.rushing_att,a.rushing_yds,
Get_Yds_Per(a.rushing_yds,a.rushing_att),a.rushing_tds,
a.receiving_rec,a.receiving_tar,a.receiving_yds,
Get_Yds_Per(a.receiving_yds,a.receiving_rec),a.receiving_tds,
a.fumbles_rec+a.fumbles_lost,a.fumbles_lost])
bigDF = df(bigList, columns=["Name","Team","Position","Week","Pass Comp","Pass Atts",
"Pass Yds","Yds/Pass","Ints","Pass TDs","Sacks","Rush Atts",
"Rush Yds","Yds/Rush","Rush TDs","Receptions","Targets",
"Rec Yds","Yds/Rec","Rec TDs","Fumbles","Fumbles Lost"])
print bigDF
Any help is appreciated.
Thanks
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Using Team Settings and Inventory Devices In Fortnite Creative
Option Value Descr...
Eliminated Player's Game Resources Don't Override, Drop, Keep, Delete
Allow Building Don't Override, None, All, Traps Only, No Traps
Win On Time Out...
Read more >Fifa 22 Custom Teams Tutorial - HOW TO SIGN ANY PLAYER!
Fifa 22 Custom Teams Tutorial Presented by EA Creator Network In this ... tutorial to update current transfers or use your Custom squad...
Read more >How to play as any club or national team in eFootball Version ...
To perform the workaround, follow these steps: From the main menu, use the RB / R1 button to navigate to Extras.
Read more >See who's on a team or in a channel - Microsoft Support
To see who's on a team or in a channel, click Manage team and look at the Members tab.
Read more >How it works: NFL Practice Squad rules, eligibility, salary, and ...
A practice squad player can not sign with his team's upcoming opponent, unless he does so six days before the upcoming game or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’ll need to use the
team
field from theplay_player
table, which records the team of the player for which that statistical event occurred. Instead of usingp[1]
for the team, trya.team
? (Although I’m not sure if theteam
field will survive an aggegation. If not, you’ll need to do it all manually.)here is an example of weekly targets and receptions per player - team is taken from play_player, which should be the team the player was on in that game (rather than his current team):
WITH aggwt AS ( SELECT pp.gsis_id, pp.player_id, pp.team, sum(pp.receiving_tar) as tar, sum(pp.receiving_rec) as rec FROM play_player AS pp INNER JOIN game as g ON pp.gsis_id = g.gsis_id WHERE g.season_type = ‘Regular’ GROUP BY pp.gsis_id, pp.player_id, pp.team )
SELECT aggwt.gsis_id, g.season_year, g.week, aggwt.player_id, p.full_name, p.position, aggwt.team, (CASE WHEN aggwt.team = g.home_team THEN g.away_team ELSE g.home_team END) as opp, aggwt.tar, aggwt.rec
FROM aggwt INNER JOIN player as p ON aggwt.player_id = p.player_id INNER JOIN game as g ON aggwt.gsis_id = g.gsis_id
WHERE p.position in (‘RB’, ‘WR’, ‘TE’)