Seven-Day Ridership Trend
Problem
You are given a DataFrame `tap` with columns `rider_id`, `rider_name`, `tapped_on`, and `fare_cents`. The pair `(rider_id, tapped_on)` is unique, and each row is one fare a rider paid when tapping into a transit station on a given day. There is at least one tap every day.
You run a transit network and want a smoothed view of revenue. For every day that has **six full days before it** in the data, compute:
- `day_total` — the total fares collected over the seven-day window ending on that day (the day itself plus the six prior days),
- `window_average` — `day_total` divided by 7, rounded to two decimal places.
Return `tapped_on`, `day_total`, and `window_average`, ordered by `tapped_on`. The earliest six days of the dataset never have a full window and are omitted.
**Example**
```text
For seven consecutive days with daily totals 100, 100, 100, 100, 100, 100, 100
the first qualifying day is the seventh, with day_total = 700 and
window_average = 100.00.
```
Input data
Example rows — the live problem includes the full dataset.
| rider_id | rider_name | tapped_on | fare_cents |
|---|---|---|---|
| 1 | Mara | 2023-01-01 | 100 |
| 2 | Theo | 2023-01-02 | 100 |
| 3 | Lena | 2023-01-03 | 100 |
| 4 | Otto | 2023-01-04 | 100 |
| 5 | Iris | 2023-01-05 | 100 |
Expected output
Your answer should return 2 rows with the columns tapped_on, day_total, window_average.
Starter code (Pandas (Python))
import pandas as pd
def seven_day_ridership_trend(tap) -> pd.DataFrame:
# Your code here
return tapSolve 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