Sustained Busy Days at the Toll Plaza
Problem
DataFrame: `tollday` (`tollday.csv`)
```text
+--------------+--------+
| Column | Type |
+--------------+--------+
| day_no | int |
| traffic_date | object |
| vehicles | int |
+--------------+--------+
day_no uniquely identifies each row; rows are numbered consecutively with no gaps.
```
Find the records of every day that is part of a run of **3 or more consecutive days** (consecutive by `day_no`) where each of those days had `vehicles` of **80 or more**.
Return the qualifying rows with columns `day_no`, `traffic_date`, and `vehicles`, ordered by `traffic_date`.
Input data
Example rows — the live problem includes the full dataset.
| day_no | traffic_date | vehicles |
|---|---|---|
| 1 | 2024-02-01 | 12 |
| 2 | 2024-02-02 | 95 |
| 3 | 2024-02-03 | 140 |
| 4 | 2024-02-04 | 70 |
| 5 | 2024-02-05 | 130 |
Expected output
Your answer should return 4 rows with the columns day_no, traffic_date, vehicles.
Starter code (Pandas (Python))
import pandas as pd
def busy_days(tollday: pd.DataFrame) -> pd.DataFrame:
# Your code here
return tolldaySolve 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