Peak Visitor Day for Each Trail
Problem
A national park logs the number of hikers counted on each trail every day. The DataFrame `trail_log` (loaded from `trail_log.csv`) has columns `(trail_id, log_date, hikers)`.
For every trail, report the day on which it recorded its highest hiker count. If the same peak count occurred on more than one day, report the earliest of those days.
Return the columns `trail_id`, `log_date`, and `hikers`.
Input data
Example rows — the live problem includes the full dataset.
| trail_id | log_date | hikers |
|---|---|---|
| 1 | 2022-04-03 | 40 |
| 1 | 2022-05-09 | 120 |
| 1 | 2022-06-21 | 310 |
| 2 | 2022-07-01 | 88 |
| 2 | 2022-07-15 | 88 |
Expected output
Your answer should return 3 rows with the columns trail_id, log_date, hikers.
Starter code (Pandas (Python))
import pandas as pd
def peak_visitor_day_per_trail(trail_log) -> pd.DataFrame:
# Your code here
return trail_logSolve 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