October 21, 2024
Chicago 12, Melborne City, USA
python

NBA_API: Is there a way to store player gamelogs in relation to the starting lineup?


I’ve tried compiling all players’ gamelogs from a certain team lets say the Celtics from the last 2 seasons into a dataframe. Then making a subset of this dataframe which returns the players’ gamelogs when a specified starting lineup played.

I’ve played around with a few different approaches and still not working. I was wondering if there is a simple approach? Ideally I want to be able to specify a specific team lineup e.g Derrick White, Jrue Holiday, Jaylen Brown, Jayson Tatum, Al Horford and want the output to be the gamelogs for each of these players when that exact lineup started.

My most recent attempt does not give the exact output I am trying to achieve and I am getting lost as at how to achieve my goal. My goal: Compile gamelogs from every player in a team for the last 2 or so seasons into a dataframe from which I can make subsets based on the starting lineup. My most recent attempt:

# Main function to compile gamelogs for the same lineup
def compile_gamelogs_for_same_lineup(team_abbreviation, season):
    team_roster = get_team_roster(team_abbreviation, season)
    
    if team_roster.empty:
        print("No roster found, exiting...")
        return pd.DataFrame()

    combined_gamelogs = pd.DataFrame()

    for _, player in team_roster.iterrows():
        player_id = player['PLAYER_ID']
        player_gamelog = get_player_gamelog_with_retries(player_id, season)
        
        if not player_gamelog.empty:
            combined_gamelogs = pd.concat([combined_gamelogs, player_gamelog], ignore_index=True)
    
    return combined_gamelogs

# Test the function
team = 'LAL'  # Los Angeles Lakers
season = '2022-23'  # NBA season (format 'YYYY-YY')

gamelogs_df = compile_gamelogs_for_same_lineup(team, season)
print("Final combined gamelogs:\n", gamelogs_df)



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video