Python Foundations for Sports Data
Zero to competent: install Python, learn pandas on real standings, and finish by building a league table from raw results.
This is the on-ramp. Ten tutorials that take you from a bare machine to comfortably loading, reshaping, joining and cleaning real sports data in pandas. Every later course on this site quietly assumes the skills in this one.
The running example is real: actual MLB standings, actual messy stat tables. By the last step you'll turn a raw list of game results into a sorted standings table — the hello-world of sports analytics, built entirely by you.
What you'll be able to do
- Set up Python, pandas and matplotlib and know what each is for
- Filter, sort, derive and aggregate columns without reaching for a spreadsheet
- Join datasets, reshape them with pivots, and clean the mess real data arrives in
- Build a standings table from raw results, end to end
The bundle contains each part's finished script, the shared helpers, and the sample data they read, with a README listing the run order - the whole course works offline.
The syllabus
Pace: A part per sitting, two weeks at an easy pace. Parts 4-8 can be taken in any order; the rest are sequential.
0 of 10 parts marked complete on this device.
Every part of this course is marked complete on this device. The capstone below is the victory lap - and the quiz will tell you if anything slipped.
- Setting Up Python for Sports Analytics: A Complete Beginner's WalkthroughEverything else assumes a working toolchain; do this once, properly.
- Pandas for Sports Data: The 12 Operations You'll Use ConstantlyThe twelve operations you'll use in every project that follows.
- Your First Sports Data Visualization with matplotlibNumbers persuade nobody until they're a picture; make your first one early.
- Filtering and Querying a DataFrameSubsetting is the real workhorse - most analysis is picking the right rows.
- Computing New Columns: Rate Stats and Feature EngineeringRaw columns are rarely the stat you want; rates and differentials come first.
- Apply and Map: Custom Column Logic in pandasFor transformations no built-in covers: your own logic, applied down a column.
- Merging and Joining Two Datasets with pandasReal questions usually need two tables; joins are how tables meet.
- Group, Pivot, and Reshape: Aggregating Sports Data Like a ProAggregation turns game-level rows into team-level answers.
- Cleaning Messy Sports Data: Real-World Fixes for Real-World FilesReal data arrives broken; this skill separates finishers from starters.
- Build a Standings Table from a Season of Game ResultsThe finale: raw results in, sorted standings out - everything above, used at once.
Check yourself
Five questions, graded on the page, nothing recorded anywhere - pick an answer and the explanation appears.
1. You have a DataFrame of teams and want only the teams with more than 90 wins. Which operation is that?
A condition that selects rows is a boolean mask - filtering. Grouping, merging and pivoting reshape or combine; they don't subset rows by a condition.
2. df.groupby('team')['runs'].mean() returns…
groupby collapses all rows sharing a key, so you get exactly one aggregate value per team.
3. Joining a standings table to a payroll table requires…
Joins match rows by key values, not by position - row order and column counts are irrelevant.
4. Which of these is a rate stat rather than a counting stat?
A rate divides by opportunity (per game, per at-bat). Totals grow with playing time even when performance doesn't.
5. One team appears as 'NYY', 'N.Y. Yankees' and 'Yankees' in the same column. That's primarily a problem of…
Same entity, several spellings - inconsistent category labels. Every groupby treats them as three different teams until you normalize.
Where next: Sports Data Visualization · Statistics for Sports Data.