Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
def fetch_season_pl_gamelogs(pid_list, season_suffix, test_mode=False):
Fetch players' game logs for a given season
:param pid_list: List of API PERSON_IDs
:param season_suffix: Season suffix string (e.g. '2020-21')
:param test_mode: Bool for just getting a few logs
:return: One dataframe with all the game log data
from nba_api.stats.endpoints import playergamelog
counter = 0 # Counter for test mode
counter_limit = 10
df_gls = list()
for pid in pid_list:
df_gl = playergamelog.PlayerGameLog(season=season_suffix, player_id=pid).player_game_log.get_data_frame()
if len(df_gl) == 0:
logger.warning(f'No games fetched for player {pid} in {season_suffix}!!')
df_gls.append(df_gl)'Found game logs for {pid} in {season_suffix} with {len(df_gl)} games')
if test_mode:
counter += 1
if counter >= counter_limit: # Limit for test mode
if len(df_gls) > 0:
df_gl = pd.concat(df_gls)
df_gl = None
return df_gl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment