Module path
fetch_games_teamwins()
Fetches Regular Season team-level game logs from the NBA API and stores them in the local SQLite database. Each game produces two rows — one for each team.
Signature
Parameters
NBA season string passed to
nba_api. The source default is "2025-2026" (full-year format). The abbreviated form (e.g., "2025-26") is also accepted by nba_api.None
Side effects:
- Creates the
gamestable inData/nba_stats.dbif it does not already exist. - Inserts or replaces rows for every team-game in the specified season.
- Prints progress and a row count to stdout.
Data source:
nba_api.stats.endpoints.leaguegamelog, Regular Season, team ("T") level.Usage example
games table columns
The function creates or updates the games table with the following columns:
| Column | Type | Description |
|---|---|---|
game_id | TEXT | Unique NBA game identifier. Part of primary key. |
game_date | TEXT | Date of the game as returned by the NBA API. |
team_id | INTEGER | NBA team identifier. Part of primary key. |
team | TEXT | Team abbreviation (e.g., "LAL"). |
opponent | TEXT | Opponent team abbreviation (e.g., "BOS"). |
team_points | INTEGER | Points scored by the team. |
opponent_points | INTEGER | Points scored by the opponent. |
team_reb | INTEGER | Total rebounds for the team. |
opponent_reb | INTEGER | Total rebounds for the opponent. |
team_ast | INTEGER | Total assists for the team. |
opponent_ast | INTEGER | Total assists for the opponent. |
home | INTEGER | 1 if the team played at home, 0 if away. |
win | INTEGER | 1 if the team won, 0 if the team lost. |
(game_id, team_id)
The home indicator is derived from the
MATCHUP field: "vs." in the matchup string means home; "@" means away.