AnalystPath

Divisive Hiking Trails

PandasMediumMid level~10 min

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.

trails
trail_idtrail_nameparklength_km
1Cedar RidgeGlacier7.5
2Foxglen LoopGlacier3.2
3Iron PassCascade12.0
4Willow BendCascade5.5
5Granite SpurOlympic9.1
difficulty_votes
vote_idtrail_idvoterscore
11va5
21vb1
31vc5
41vd2
51ve4

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 trails

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