Created
February 3, 2022 09:09
-
-
Save databyjp/1dd58b64ca2b0604680d1bb649c75217 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}!!') | |
else: | |
df_gls.append(df_gl) | |
logger.info(f'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 | |
break | |
if len(df_gls) > 0: | |
df_gl = pd.concat(df_gls) | |
else: | |
df_gl = None | |
return df_gl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment