swar / nba_api

An API Client package to access the APIs for NBA.com
MIT License
2.36k stars 518 forks source link

Can't get a player's shot chart detail from a specific game #202

Open robbylewis7 opened 3 years ago

robbylewis7 commented 3 years ago

I'm trying to get a player's shot data from a specific game, but can't seem to get anything to return. What am I not seeing?

`import sys

import numpy as np import pandas as pd

from nba_api.stats.static import players from nba_api.stats.endpoints import shotchartdetail from nba_api.stats.endpoints import playercareerstats

def get_player_shotchartdetail(player_name):

nba_players = players.get_players()
player_dict = [player for player in nba_players if player['full_name'] == player_name][0]

career = playercareerstats.PlayerCareerStats(player_id=player_dict['id'])
career_df = career.get_data_frames()[0]

shotchartlist = shotchartdetail.ShotChartDetail(team_id='1610612738',
                                                player_id=int(player_dict['id']),
                                                season_type_all_star=['Regular Season'],
                                                season_nullable='2017-18',
                                                game_id_nullable='0041700305',
                                                context_measure_simple="PTS").get_data_frames()

return shotchartlist[0], shotchartlist[1]`
rsforbes commented 3 years ago

Played around with this for about an hour. I got the same result as you even though there appears to be data that the NBA has on the game (https://www.nba.com/game/bos-vs-cle-0041700305/game-charts). I was able to pull data for the most recent game for the Celtics. One thing I noticed is that the ShotChartDetail only returns shots that were made by the player. Example: Tristan Thompson when 4-6 FGM and the following call only returns the 4 that were made. There are a number of other calls relating to shot detail. Perhaps one of the others would prove useful. Good luck!

import pandas as pd

from nba_api.stats.static import players
from nba_api.stats.endpoints import shotchartdetail
from nba_api.stats.endpoints import playercareerstats

player = players.find_players_by_full_name("Tristan Thompson")[0]
shotchartlist = shotchartdetail.ShotChartDetail(team_id='1610612738',player_id=player['id'], game_id_nullable='0022000350')
games = shotchartlist.get_data_frames()[0]
games.head()
lukegeorge85 commented 3 years ago

RE: only returning shots made. The default context for shotchartdetail is PTS which I assume only returns shots resulting in points. I changed this to FGA which I would assume is Field Goals Attempted and it included missed shots.

shotchartdetail.ShotChartDetail(player_id=player_id, team_id=team_id, context_measure_simple='FGA')

lukegeorge85 commented 3 years ago

I did a bit more digging on this. I cycled through team rosters for 5 seasons and called the shot charts for each team/player combination: shotchartdetail.ShotChartDetail(player_id=player_id, team_id=team_id, context_measure_simple='FGA')

Each request returned shot chart data for multiple games. I joined them all together and analysed the GAME_IDs that were present. All GAME_IDs where the first non-zero number is a "2" e.g. 0022000445 had shot chart data. Any GAME_IDs where the first non-zero number was a "1" or a "4" did not have shot chart data.

Not sure what the significance of this but I hope this helps trigger some ideas for someone as to how to get to the shot chart data for these games.

george-xy commented 1 year ago

I can only get Made Shot data, is there Made Out data in the document, and if so, can you write an example for me