AnalystPath

Percentile Standing of Each Runner

PandasMediumMid level~10 min

Problem

You are given a DataFrame `runners` with columns `runner_id`, `bracket_id`, and `score`. Within each bracket, compute each runner's percentile standing using the formula `(rank - 1) * 100 / (total_runners - 1)`, where `rank` is the position by descending score (ties share the same lower rank) and `total_runners` is the number of runners in the bracket. If a bracket has only one runner, the standing is 0. Round the standing to 2 decimals. Return columns `runner_id`, `bracket_id`, and `standing`. Row order does not matter.

Input data

Example rows — the live problem includes the full dataset.

runners
runner_idbracket_idscore
22650
82650
71920
11610
31530

Expected output

Your answer should return 5 rows with the columns runner_id, bracket_id, standing.

Starter code (Pandas (Python))

import pandas as pd

def percentile_standing(runners) -> pd.DataFrame:
    # Your code here
    return runners

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