-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create joins #171
Comments
I have no idea if it is the most efficient but why not just create a second query once you have a single game in hand? import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2012, season_type='Regular')
q.player(full_name='Peyton Manning')
for g in q.as_games():
game_info = map(str, [g.gsis_id, g.week, g.season_type, g.season_year, g.start_time, g.home_team, g.home_score_q1, g.home_score_q2, g.home_score_q3, g.home_score_q4])
new_q = nfldb.Query(db)
new_q.game(gsis_id=g.gsis_id)
new_q.player(full_name='Peyton Manning')
for p in new_q.as_aggregate():
player_info = map(str, [p.passing_tds, p.rushing_tds, p.kicking_fga, p.kicking_fgm, p.fumbles_tot, p.fumbles_lost, p.kicking_xpa])
print game_info + player_info
|
I use materialized views for weekly and season-long statistics and then add indexes on the materialized views. Here is an example for weekly targets: CREATE MATERIALIZED VIEW cs_targets AS WITH aggwt AS ( SELECT FROM aggwt WHERE |
First I'd like to thank you for your great work!
I'm working on a small project where we have quite a complex SQL query which aggregates statistics from the
play
andagg_play
table for each game. So far I save it as csv and later have to import it to python. I'd like to skip this step and do it directly with the nfldb methods.I tried a few things but currently I can not get it to work like I would.
I found this file https://github.com/BurntSushi/nfldb/blob/master/tests/test_sql.py but it seems that the join methods are not visible when importing nfldb. I copied
join
andjoins_to
to my source file and tried to use. But it doesn't return anything and it also doesn't change anything. But since it is in the test folder maybe it shouldn't be used?I tried to loop over games and then over e.g. play like this.
But this does not work because of course in the loop the query is set to only this game and I am not able to loop over play and play as_aggregate() in nested loops, this does not make much sense....
My desired output would be like the table in the screenshot. Do you see any way how this can be done with the nfldb library?
The text was updated successfully, but these errors were encountered: