Python practice: GroupBy Aggregations & Named Multi-Metric Reports

Chapter 25 · 8 questions · included in full access

  1. Question 1 · easy

    Split-apply-combine concept

    In pandas, what happens during the three stages of the split-apply-combine pattern when calling df.groupby("Region")["Revenue"].sum()?

    Solve it in your browser
  2. Question 2 · easy

    Calculate mean revenue by region

    Load "sales.csv". Calculate the average Revenue for each Region using .groupby("Region")["Revenue"].mean(). Print the average revenue for "North" rounded to 2 decimal places using round(means["North"], 2):

    Solve it in your browser
  3. Question 3 · medium

    Two-column grouping: Region and Category

    Load "sales.csv". Group by ["Region", "Category"] and sum "Revenue". Print the total revenue for the ("North", "Sheets") combination:

    Solve it in your browser
  4. Question 4 · easy

    Tally group frequencies with size()

    Load "sales.csv". Group by "Region" and call .size() to count rows per region. Print the count for "South":

    Solve it in your browser
  5. Question 5 · medium

    Multi-metric aggregation with .agg()

    Load "sales.csv". For each Category, compute the minimum and maximum Revenue using .groupby("Category")["Revenue"].agg(["min", "max"]). Print the maximum revenue for "Sheets":

    Solve it in your browser
  6. Question 6 · medium

    Named aggregation with custom output columns

    Load "sales.csv". Use named aggregation on .groupby("Region") to calculate total_rev=("Revenue", "sum") and order_count=("OrderID", "count"). Print the total_rev for "West":

    Solve it in your browser
  7. Question 7 · easy

    Reset index to produce flat export table

    Load "sales.csv". Sum Revenue by Region, call .reset_index(), and print the column names of the resulting DataFrame as a list (list(flat.columns)):

    Solve it in your browser
  8. Question 8 · hard

    Executive sales performance report

    Load "sales.csv". Group by "Rep" and use .agg() to compute total_rev=("Revenue", "sum") and orders=("OrderID", "count"). Reset the index, sort by "total_rev" descending, and print the top rep name (report.iloc[0]["Rep"]):

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing