Free real-world Pandas exercises, with solutions

If you want to get better at Pandas, the hard part isn’t finding tutorials. It’s finding problems worth solving. Most exercises hand you a tidy little table of five rows and ask you to sum a column — which teaches you the syntax, but nothing about the job.

For the last 3.5 years, I’ve written Bamboo Weekly, a weekly set of Pandas exercises built on real, current, public data: coal plants, earthquakes, Netflix viewing hours, government corruption indices, and IPO filings, among many others. Real data, which means the columns are named badly, the dates are strings, and answering the interesting questions takes four steps rather than one.

As of this week, every issue older than two years is free — no signup, no subscription. That’s issues #1 through #78, with 155 posts, and more than 500 exercises with fully worked-out solutions. Another opens every week as it passes its second birthday.

Why real data changes what you learn

A toy dataset teaches you groupby. A real one teaches you that the column is a string when you expected a number, that three rows have a country name nobody standardised, and that observed=True changes your answer.

Here is an actual example from the archive — the Global Coal Plant Tracker, one row per generating unit, asking which countries emit the most CO2 from coal:

import pandas as pd

url = ('https://www.bambooweekly.com/content/files/wp-content/uploads/2024/02/'
       'global-coal-plant-tracker-january-2024.xlsx')

(
    pd.read_excel(url, sheet_name='Units',
                  usecols=['Country', 'Annual CO2 (million tonnes / annum)'])
    .groupby('Country')
    ['Annual CO2 (million tonnes / annum)']
    .sum()
    .sort_values(ascending=False)
    .head(3)
)
Country
China             10091.0
India              3941.4
United States      1999.9

Four methods, one question, and every step is one you would actually use at work. That is the whole idea. You improve your data-analysis muscle memory with Bamboo Weekly, and then you’re ready to tackle problems at work with greater confidence.

Method guides, with the mistakes people actually make

Alongside the exercises, I’ve written up 16 of the Pandas methods that come up most often. Each one covers what the method does, the argument forms worth knowing, a worked example on a real dataset you can load from the URL in the code, and the mistakes that catch people — all verified against Pandas 3.

Reading data

  • read_csv — the arguments that earn their keep
  • read_excel — sheet names, and why the first sheet is usually wrong

Selecting and filtering

  • loc — labels, conditions, and why chained assignment silently fails
  • iloc — positions, and where they stop matching labels
  • pd.col — new in Pandas 3, and where it does not work

Reshaping and transforming

  • assign — new columns without mutating anything
  • drop — and when filter is the better tool
  • sort_values — several keys, opposite directions
  • set_index — the index earns its keep

Grouping and aggregating

  • groupby — split, apply, combine
  • agg — named aggregation, and why it beats the dict form
  • pivot_table — and how it differs from pivot
  • value_counts — the second thing to run on new data

Dates and times

  • to_datetime — and why guessing the format corrupts data quietly
  • resample — including the frequency codes nobody remembers

Method chaining

  • pipe — how to end a chain in a Plotly chart

If you are upgrading to Pandas 3, two of those are worth reading first. pd.col replaces most of the lambdas in your chains, and resample will break your code outright: 'M', 'Y', 'T', 'H' and 'S' no longer warn, they raise ValueError.

Try one without installing anything

Each method guide links to a matching exercise on the LernerPython practice system, which runs entirely in the browser. No installation, no signup, no account.

Where to start

Pick a method you use constantly and read its page. You will probably recognize one or more of the mistakes, and see how your code can be cleaner, clearer, and more efficient. Or open the archive to an interesting issue, and try the questions before reading the solutions. Peeking at the answers before you’ve tried your hand at solving the problem yourself is harder, but it also teaches you more.

New issues go out every week, and the two-year-old ones keep opening up behind them.