Riders per Ferry I
Problem
A harbour logs ferry departures in a DataFrame `ferries` with columns `(ferry_id, depart_time)` and rider arrivals in a DataFrame `riders` with columns `(rider_id, arrive_time)` (both loaded from CSVs). Times are integers; `ferry_id` and `rider_id` are unique.
Each rider boards the next ferry whose `depart_time` is greater than or equal to that rider's `arrive_time`. Return `ferry_id` and `rider_count` (how many riders board it) for every ferry, including ferries nobody boards, ordered by `ferry_id` ascending.
Input data
Example rows — the live problem includes the full dataset.
| ferry_id | depart_time |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | 7 |
| rider_id | arrive_time |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 3 | 5 |
| 4 | 6 |
| 5 | 7 |
Expected output
Your answer should return 3 rows with the columns ferry_id, rider_count.
Starter code (Pandas (Python))
import pandas as pd
def riders_per_ferry_i(ferries, riders) -> pd.DataFrame:
# Your code here
return ferriesSolve 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