Enhanced PBP

StatsNbaEnhancedPbpLoader loads pbp data for a game and creates EnhancedPbpItem objects for each event

Enhanced data for each event includes current players on floor, score, fouls to give and number of fouls committed by each player, plus additional data depending on event type

The following code will load pbp data for game id “0021900001” from a file located in a subdirectory of the /data directory

from pbpstats.data_loader import StatsNbaEnhancedPbpFileLoader, StatsNbaEnhancedPbpLoader

source_loader = StatsNbaEnhancedPbpFileLoader("/data")
pbp_loader = StatsNbaEnhancedPbpLoader("0021900001", source_loader)
print(pbp_loader.items[0].data)  # prints dict with the first event of the game
class pbpstats.data_loader.stats_nba.enhanced_pbp.loader.StatsNbaEnhancedPbpLoader(game_id, source_loader)[source]

Bases: pbpstats.data_loader.stats_nba.pbp.loader.StatsNbaPbpLoader, pbpstats.data_loader.nba_enhanced_pbp_loader.NbaEnhancedPbpLoader

Loads stats.nba.com source enhanced pbp data for game. Events are stored in items attribute as EnhancedPbpItem objects

Parameters:
Raises:

InvalidNumberOfStartersException: If all 5 players that start the period for a team can’t be determined. You can add the correct period starters to overrides/missing_period_starters.json in your data directory to fix this.

Raises:

EventOrderError: If rebound event is not immediately following a missed shot event. You can manually edit the event order in the pbp file stored on disk to fix this.

data_provider = 'stats_nba'
parent_object = 'Game'
resource = 'EnhancedPbp'
class pbpstats.data_loader.stats_nba.enhanced_pbp.file.StatsNbaEnhancedPbpFileLoader(file_directory)[source]

Bases: pbpstats.data_loader.stats_nba.pbp.file.StatsNbaPbpFileLoader

A StatsNbaEnhancedPbpFileLoader object should be instantiated and passed into StatsNbaEnhancedPbpLoader when loading data from file

Parameters:file_directory (str) – Directory in which data should be loaded from. The specific file location will be stats_<game_id>.json in the /pbp subdirectory.
class pbpstats.data_loader.stats_nba.enhanced_pbp.web.StatsNbaEnhancedPbpWebLoader(file_directory=None)[source]

Bases: pbpstats.data_loader.stats_nba.pbp.web.StatsNbaPbpWebLoader

A StatsNbaEnhancedPbpWebLoader object should be instantiated and passed into StatsNbaEnhancedPbpLoader when loading data directly from the NBA Stats API

Parameters:file_directory (str) – (optional, use it if you want to store the response data on disk) Directory in which data should be either stored. The specific file location will be stats_<game_id>.json in the /pbp subdirectory. If not provided response data will not be saved on disk.