Back to Practice
#0154
Cumulative Sales by Customer
MediumPandas25 min20 XP
Problem
Given a dataframe with customer, date, and amount, return it sorted by customer/date with a cumulative_amount column per customer.
Why This Matters
Running totals are used in customer value, retention history, inventory movement, and financial reporting.
Function Signature
def add_cumulative_sales(df):
Examples
Example 1
Inputcustomer A has amounts 10 then 5; customer B has 7
OutputA cumulative values 10, 15; B cumulative value 7
The running total resets for each customer.
Constraints
- Return the exact requested value.
- Handle empty or small inputs when the prompt allows them.
- Keep the code readable and deterministic.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputcustomer A has amounts 10 then 5; customer B has 7
ExpectedA cumulative values 10, 15; B cumulative value 7
The running total resets for each customer.
Hidden Test Categories
empty or smallest inputduplicates or repeated valueslarger realistic input