pandas: Monthly Revenue by Cohort

medium
Unit 4 · Statistics & Experimentation0/3 to milestone

You're given a DataFrame of orders with columns user_id, order_date (string YYYY-MM-DD) and amount.

Implement cohort_revenue(df) that returns a DataFrame:

  • index: cohort month (YYYY-MM string) — the month of each user's first order
  • columns: order month (YYYY-MM string)
  • values: total revenue, with missing combinations filled with 0

Rows and columns sorted ascending.

#pandas#groupby#cohorts1 visible + 0 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
pandas: Monthly Revenue by Cohort · TechGradify