12 tutorials

Basketball

The NBA's stats API is powerful but picky. Learn to pull it politely, then build standings, ratings and shot charts.

Level:
A current-standings DataFrame from nba_api, with the proper headers baked in.
Basketball Beginner

Pull Your First NBA Data with nba_api

Pull NBA standings with nba_api, with the browser headers and retry logic stats.nba.com demands. Includes exactly what to do when the endpoint refuses to answer.

~9 min
A two-condition filter that finds the contenders, highlighted on a chart.
Basketball Beginner

Filtering and Querying a DataFrame

Ask your data a question: use boolean masks and .query() to select the rows that match multiple conditions, then highlight that filtered set on a chart of every team.

~5 min
A side-by-side bar chart of offensive and defensive rating for the top NBA teams.
Basketball Beginner

Grouped Bar Charts: Compare Two Metrics Side by Side

A stacked bar shows composition; a grouped bar shows comparison. Nudge two bar series apart with a half-width offset to put each team's offense and defense next to each other - the chart for 'which is bigger, A or B, within each group?'

~5 min
A ranked net-rating table styled like a real dashboard, exported as an image.
Basketball Intermediate

Build a Team Net-Rating Dashboard Table

Combine offensive and defensive ratings into a ranked net-rating table, then style it into a dashboard-quality figure you can drop into a report.

~8 min
A half-court drawn in matplotlib with a player's makes and misses plotted on it.
Basketball Intermediate

Draw an NBA Shot Chart with matplotlib

Draw a regulation half-court from scratch in matplotlib, then plot a player's makes and misses in court coordinates for a real, shareable shot chart.

~10 min
A hexbin heatmap of where the entire league takes its shots.
Basketball Intermediate

Draw a League-Wide NBA Shot Heatmap

Plot thousands of NBA shots as a hexbin density heatmap on a court you draw yourself, revealing the modern shot-selection fingerprint: the rim and the three-point line.

~8 min
A home-vs-away win table broken down by margin of victory, charted as home win share.
Basketball Intermediate

Crosstabs: Build a Contingency Table to Test Home Advantage

Turn a hunch into a table. pd.crosstab() counts how two categorical variables co-occur - here who won against how big the margin was - and normalize='index' converts those counts into the rates that reveal how home advantage grows with the blowout.

~5 min