-
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
importing nfldb on iPython Notebook (Jupyter) #159
Comments
What is your script doing that takes that long to run? A common query rarely takes more than seconds to complete. If you are collecting the entirety of the database through each pass maybe you should consider re-thinking your query to make it more efficient. Maybe if I could see your code I'd be able to provide a little more input.
For this issue, I'd start there...if the environment is not set up properly, how is |
So I got nfldb to work in with Jupyter Notebook and ran this:
The reason it was difficult without Jupyter Notebook is I put this into a DataFrame, and I had to wait 15+ minutes every time I wanted to change something or do something to the DataFrame. I figured out how to get this to work in Jupyter Notebook, but if you know how to shorten the amount of time that the query takes that'd be great. |
Well, without deconstructing the code too much, what you are doing is generating a list of more than 1800 players that appeared during the 2015 season. With that list of players, you are then going through each of the seventeen weeks of the 2015 season 1800 times. When you do the I'll try to spend some time with this tonight to see if I can't give some better tips. |
Ok, thank you. |
#I know I can make this part shorter, but I just haven't gotten to it yet.
q = nfldb.Query(db)
q.game(season_year=2015,season_type='Regular')
q.player(position__ne='K').player(position__ne='P').player(position__ne='DE').player(position__ne='CB')
q.player(position__ne='OLB').player(position__ne='FS').player(position__ne='DT').player(position__ne='T')
q.player(position__ne='SS').player(position__ne='NT').player(position__ne='OG').player(position__ne='MLB')
q.player(position__ne='LB').player(position__ne='C').player(position__ne='ILB').player(position__ne='LS')
q.player(position__ne='DB').player(position__ne='LB').player(position__ne='G')
for g in q.as_players():
playerList.append([str(g.full_name),str(g.team),str(g.position)]) You could replace that block with something like this: playerList = [[g.full_name, g.team, g.position] for g in q.as_players() if str(g.position) in ['QB', 'RB', 'TE', 'WR', 'FB']] Though, as you note, that won't do anything to pare down the amount of time you spend in the time intensive chunk of code (though on my laptop that takes closer to 9 seconds per week, not 15 minutes). You're doing the right thing by substituting the play |
Ok, thanks for the help. I shortened it as you suggested. |
@theSanchize3 how did you end up solving your jupyter notebook issue mentioned above? |
I decided switch to iPython notebook because it was very annoying having to repeatedly wait 20+ minutes to execute code when I wasn't even editing the part of the code that takes up the bulk of the time. However, when I tried to import nfldb, it gave me an error. The first time, it said there was no nfldb module that exists. I added the path that was needed, but now I have a different error.
I'm not sure what this means. I tried importing psycopg2, but that returned this error:
Please help with this.
Thanks.
The text was updated successfully, but these errors were encountered: