AnalystPath

Daily Spend by Payment Channel

PandasHardSenior level~10 min

Problem

A ride-hailing app records each payment a rider makes, tagged with the channel they paid through, in a DataFrame `payment` (`payment.csv`).

```text
+-------------+--------+
| Column | Type |
+-------------+--------+
| rider_id | int |
| paid_on | object |
| channel | object |
| amount | int |
+-------------+--------+
```

There may be several rows per rider per day. `channel` is either `'app'` or `'kiosk'`.

Write a function that reports, for every date present in the data, the number of riders and the total amount spent across three channels: `'app'`, `'kiosk'`, and `'both'`. A rider counts toward `'both'` on a date when they paid through both `'app'` and `'kiosk'` that same date (and then counts only toward `'both'`, not the individual channels). Every date must show all three channels even when a channel has no riders, reporting 0 riders and 0 total in that case. Return columns `pay_date`, `channel`, `total_amount`, and `total_riders` in any order.

Input data

Example rows — the live problem includes the full dataset.

payment
rider_idpaid_onchannelamount
12023-07-01app100
12023-07-01kiosk100
22023-07-01app100
22023-07-02app100
32023-07-01kiosk100

Expected output

Your answer should return 6 rows with the columns pay_date, channel, total_amount, total_riders.

Starter code (Pandas (Python))

import pandas as pd

def daily_channel_spend(payment: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return payment

Solve this Pandas question free

Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related Pandas questions