seemethere / nba_py

Python client for NBA statistics located at stats.nba.com
BSD 3-Clause "New" or "Revised" License
1.05k stars 255 forks source link

How to get the game_ids for entire season/playoff 2017-18 #121

Closed chingwen823 closed 6 years ago

chingwen823 commented 6 years ago

I had read the docs, and probably missed some thing important can't find a simple way to get the game ids for season

any one tell me how to do it?

jaypeedevlin commented 6 years ago

I've been wanting to do some analysis on playoff games, so was looking for a way to do the same thing. As far as I can work out, there's no endpoint that will give you all game id's for a given season, so there's no way the package can do that for you.

What I ended up doing was using nba_py.Scoreboard() which will return some basic info (including game id's for a given date. I iterated through dates starting from the first playoff game to today, and concatenated all the data together. Here's a snippet of my method:

import datetime as dt
import pandas as pd
import nba_py

d = dt.date(2018,4,14) # date of first playoff game

playoff_games = []

while d < dt.date.today():
    s = nba_py.Scoreboard(day=d.day,month=d.month,year=d.year)
    playoff_games.append(s.game_header())
    d += dt.timedelta(1)

all_playoffs = pd.concat(playoff_games)

At the end of this, you'll have all_playoffs, a pandas dataframe, and the GAME_ID column will contain all the game _ids for the period you select.

chingwen823 commented 6 years ago

Thank you for this wonderful reply.

I did a similer thing to get all the game ids, instead of iteration by date, i iterated by players.

Warrior just won the game!

Kyle1993 commented 6 years ago

This way can't separate the playoff game and regular game hold in a same day

jaypeedevlin commented 6 years ago

@Kyle1993 the final regular season games were played on April 11th, the first playoff games were played on April 14th, there are no days with both playoff and regular season games.

Ref:

image

chingwen823 commented 6 years ago

Thanks jaypeedevlin issue close