roclark / sportsipy

A free sports API written for python
MIT License
482 stars 188 forks source link

Possible to get player-level box score data for NCAAB? #341

Closed kmedved closed 4 years ago

kmedved commented 4 years ago

Hello - I'm interested in downloading player-level box-score using this package? Is that possible? When I use the Boxscore module in sportsreference.ncaab.boxscore, it returns team-level box score information, which is wonderful, but I don't see a way to get the same data on a player-level (e.g., Carsen Edwards took 10 FGA, etc...).

Is that sort of data available through this package?

roclark commented 4 years ago

Hey @kmedved, thanks for the question! As of one of the more recent updates, the Boxscore class now includes both a home_players and away_players property which is a list of BoxscorePlayer instances of every player on the home and away teams, respectively. This allows you to find per-player stats during a particular game. I am planning on updating all interfaces down the road to make it easier to work between and find various players, as I feel this part is a little clunky, but you can get the desired information with the following:

from sportsreference.ncaab.boxscore import Boxscore

game = Boxscore('2019-03-23-20-purdue')
for player in game.home_players:
    print(player.name, player.field_goal_attempts)

This will print the name and number of field goal attempts for every player on the home team (Purdue) for the game. If you only desire Carsen Edwards' stats, you could add an if statement in the loop, but as mentioned, I hope to make this easier down the line.

Is this along the lines of what you are looking for?

kmedved commented 4 years ago

Is it, yes @roclark. Is there any way to get all of a players' box-score stats for that given game, or do I need to add separate calls for each stat (e.g., player.field_goal_attempts, player.assists, etc...) type calls there? If so, that's fine - I just want to find the most efficient way to do this.

FYI - I am the creator of an NBA projection system DARKO (https://apanalytics.shinyapps.io/DARKO/), and am looking to extend it to NCAA ball, so I need player-game-level box-score data for that. This package will be a big help. Thanks again!

roclark commented 4 years ago

I included a dataframe property in the BoxscorePlayer class (which you can find here) that converts all relevant metrics for an individual player in a game to a pandas DataFrame. That would likely be the best way to get all stats for a specific player in a game, and you can manipulate the DataFrame as you see fit from there.

I did some poking around DARKO and that looks awesome!! I love projects like this which really push sports statistics and predictions to the next level. And extending it to NCAAB would be cool too! Let me know if there are ways to further expand the package to get more relevant information and I will see what I can do.

Thanks again!

roclark commented 4 years ago

Closing as no new updates. Feel free to re-open or create a new issue if further assistance is required. Thanks!

kmedved commented 4 years ago

Thanks @roclark - this worked great. No further help needed on this. Appreciate the quick turnaround and responsiveness!