AnalystPath

Sustained Busy Days at the Toll Plaza

PandasHardSenior level~10 min

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.

tollday
day_notraffic_datevehicles
12024-02-0112
22024-02-0295
32024-02-03140
42024-02-0470
52024-02-05130

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 tollday

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