Divisive Hiking Trails
Problem
Two CSV files describe trail ratings. `trails.csv` holds each trail (`trail_id`, `trail_name`, `park`, `length_km`); `difficulty_votes.csv` records hiker votes (`vote_id`, `trail_id`, `voter`, `score`) where each score is 1 to 5. A trail is 'divisive' when it has at least five votes, at least one vote of 4 or higher, and at least one vote of 2 or lower. The divisiveness is the share of extreme votes (a score of 2 or lower, or 4 or higher) out of all votes, rounded to two decimals as `divisiveness`. Report only trails whose divisiveness is at least 0.6. Sort by `divisiveness` descending, then by `trail_name` descending.
Input data
Example rows — the live problem includes the full dataset.
| trail_id | trail_name | park | length_km |
|---|---|---|---|
| 1 | Cedar Ridge | Glacier | 7.5 |
| 2 | Foxglen Loop | Glacier | 3.2 |
| 3 | Iron Pass | Cascade | 12.0 |
| 4 | Willow Bend | Cascade | 5.5 |
| 5 | Granite Spur | Olympic | 9.1 |
| vote_id | trail_id | voter | score |
|---|---|---|---|
| 1 | 1 | va | 5 |
| 2 | 1 | vb | 1 |
| 3 | 1 | vc | 5 |
| 4 | 1 | vd | 2 |
| 5 | 1 | ve | 4 |
Expected output
Your answer should return 2 rows with the columns trail_name, divisiveness.
Starter code (Pandas (Python))
import pandas as pd
def find_divisive_trails(trails, difficulty_votes) -> pd.DataFrame:
# Your code here
return trailsSolve 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