Level 2: pandas Data Science Exercises
Level 2 teaches pandas, the tool data analysts use every day to explore tables. You build DataFrames from API-style records, filter orders, add computed columns, rank a leaderboard and total revenue per city, all with small tables you can read at a glance.
Each lesson names one trap that pandas users hit for real: s[0] reading
a label instead of a position, the missing double brackets, or the chained
assignment that silently changes nothing. Real pandas runs in your browser,
and the tests check your code as soon as you click Run Tests.
The 10 exercises in this level
- 1 pandas Series Labels and positions A Series is a column of values with labels. Read it by label or by position without mixing the two up. Start here — no prerequisites
- 2 pandas DataFrames Tables from API data Build a DataFrame from a list of records like an API returns, keep only the columns you need and check its shape. Start here — no prerequisites
- 3 Selecting pandas Columns df["a"] or df[["a", "b"]] Pick one column as a Series or several as a new DataFrame, and avoid the missing-brackets mistake. Recommended first: pandas DataFrames
- 4 Filtering Rows in pandas Masks and isin() Keep the orders from a few cities with a boolean mask and isin(), the pandas way to say "is one of". Recommended first: Selecting pandas Columns
- 5 New Columns in pandas Column maths without loops Add a price-with-VAT column to a product table with one vectorized expression instead of looping over the rows. Recommended first: Selecting pandas Columns
- 6 pandas loc Updates Change only the matching rows Apply a bulk discount to the right rows with df.loc[mask, column], and avoid the chained assignment that silently changes nothing. Recommended first: Filtering Rows in pandas, New Columns in pandas
- 7 Sorting a pandas DataFrame sort_values and reset_index Build a leaderboard (highest score first, ties by name) and renumber its rows with reset_index(). Recommended first: Selecting pandas Columns
- 8 pandas groupby Totals per category Total the revenue of each city with groupby(): split the rows into groups, sum each one and return the result as a plain dict. Recommended first: Filtering Rows in pandas
- 9 pandas value_counts How often each value appears Count how often each browser, plan or answer appears with value_counts(), and turn the counts into percentages. Recommended first: pandas Series
- 10 Project: pandas Sales Report Everything from this level From a raw order table, keep the paid orders, compute line totals, add them up per product and rank the products: a real pandas report. Recommended first: pandas groupby, pandas loc Updates, Sorting a pandas DataFrame
Frequently asked questions
- What is the difference between a Series and a DataFrame?
- A Series is one column of values with labels (the index). A DataFrame is a table of Series that share the same index: `df["price"]` gives you one of them.
- Should I use loc or iloc?
- `loc` selects by labels and conditions, `iloc` by position. Use `loc` to update matching rows and `iloc` for "the first row" or "the last value".
- What does SettingWithCopyWarning mean?
- You probably wrote into a temporary copy, as in `df[mask]["col"] = x`, so `df` did not change. Write `df.loc[mask, "col"] = x` instead; the "pandas loc Updates" exercise shows how.
- Is this the same pandas as in Jupyter or Google Colab?
- Yes. It is real pandas running in your browser, so everything you write here works the same in Jupyter, Colab or a script on your computer.