dblackrun / pbpstats

A package to scrape and parse NBA, WNBA and G-League play-by-play data.
MIT License
86 stars 18 forks source link

Get season averages for player #5

Open gabrielfior opened 4 years ago

gabrielfior commented 4 years ago

Is it possible to get the season averages for a player (like here) through a function call? My concrete use-case would be to get season averages (points per game, if possible also shot percentage from each area of floor).

dblackrun commented 4 years ago

No, it would be pretty inefficient to get season totals through here (parsing the play-by-play of every game every time) rather than storing the possession and game data produced here in a database and using that for whatever you need.

gabrielfior commented 4 years ago

Sure, to compute the averages from each player/team every time would be inefficient. My question was if there is an automated way to get the player averages from each season, for instance from here.

Thanks!

dblackrun commented 4 years ago

No, this package just handles play-by-play data, if you are looking to handle some of the other api endpoints you should try one of the other python nba packages. I don't use any of them so I can't offer advice on which one is best, but I know there are multiple.

pauldevos commented 4 years ago

here

Gabrielfior, to do the page you listed would require n number of player API calls. You can get ALL the players season averages (or per100, totals, etc) with a single API call from this endpoint:

https://stats.nba.com/stats/leaguedashplayerstats

Provided you have a header with a referrer (now explicitly required by the stats.nba.com site) you can easily just pull this data with requests and Python.

r = requests.get(URL, header=your_header).json()

https://stats.nba.com/stats/leaguedashplayerstats?College=&Conference=&Country=&DateFrom=&DateTo=&Division=&DraftPick=&DraftYear=&GameScope=&GameSegment=&Height=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PORound=0&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerExperience=&PlayerPosition=&PlusMinus=N&Rank=N&Season=2019-20&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&StarterBench=&TeamID=0&TwoWay=0&VsConference=&VsDivision=&Weight=

However, if you want someone else's API wrapper, it looks like nba_api is the most kept up and up to date one out there as nba_py looks like it's 4+ years old and may break with some of the changes made by the developers on the stats.nba.com site.

https://github.com/swar/nba_api