Daily Spend by Payment Channel
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.
| rider_id | paid_on | channel | amount |
|---|---|---|---|
| 1 | 2023-07-01 | app | 100 |
| 1 | 2023-07-01 | kiosk | 100 |
| 2 | 2023-07-01 | app | 100 |
| 2 | 2023-07-02 | app | 100 |
| 3 | 2023-07-01 | kiosk | 100 |
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 paymentSolve 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