import pandas as pdimport requestsdef get_hustle(year, ps=False): """Fetch hustle statistics from NBA.com Stats API. Args: year: Season ending year (e.g., 2025 for 2024-25 season) ps: Boolean, True for playoffs, False for regular season """ stype = "Playoffs" if ps else "Regular%20Season" season = str(year-1) + '-' + str(year)[-2:] # NBA.com Stats API endpoint url = ( 'https://stats.nba.com/stats/leaguehustlestatsplayer' '?College=&Conference=&Country=&DateFrom=&DateTo=&Division=' '&DraftPick=&DraftYear=&GameScope=&Height=&ISTRound=' '&LastNGames=0&LeagueID=00&Location=&Month=0' '&OpponentTeamID=0&Outcome=&PORound=0&PaceAdjust=N' f'&PerMode=Totals&PlayerExperience=&PlayerPosition=' f'&PlusMinus=N&Rank=N&Season={season}&SeasonSegment=' f'&SeasonType={stype}&TeamID=0&VsConference=&VsDivision=&Weight=' ) # Required headers for NBA.com API headers = { "Host": "stats.nba.com", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0", "Accept": "application/json, text/plain, */*", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate, br", "Connection": "keep-alive", "Referer": "https://stats.nba.com/" } # Make the request response = requests.get(url, headers=headers) json_data = response.json() # Extract data from JSON response data = json_data["resultSets"][0]["rowSet"] columns = json_data["resultSets"][0]["headers"] # Create DataFrame df = pd.DataFrame(data, columns=columns) df['year'] = year return df# Collect 2024-25 regular season hustle statsdf = get_hustle(2025, ps=False)print(df.head())print(f"\nCollected {len(df)} players")print(f"\nColumns: {df.columns.tolist()}")# Save to CSVdf.to_csv('hustle_2025.csv', index=False)
You’ve successfully collected your first dataset! The CSV file contains hustle metrics like deflections, charges drawn, screen assists, and loose balls recovered.
Master CSV files contain all seasons combined for easy multi-year analysis:
import pandas as pd# Load master file with all seasonsall_passing = pd.read_csv('passing.csv')# Filter to specific player across all yearsluka_passing = all_passing[ all_passing['Name'].str.contains('Luka Doncic', case=False)]print(luka_passing[['Name', 'year', 'Assists', 'Potential Assists', 'High Value Assist %', 'on-ball-time%']])