AnalystPath

Pick the Best Courier for Each Delivery Zone

PandasMediumMid level~10 min

Problem

A food-delivery company assigns one courier to each delivery zone. Two DataFrames are loaded from CSV: `couriers` (`courier_id`, `capability`, `skill_level`) lists each courier's vehicle capabilities and skill level, and `zones` (`zone_id`, `capability`, `needed_level`) lists the capabilities a zone requires and how critical each is (level 1 to 5).

A courier is eligible for a zone only if they possess every capability the zone requires. For each eligible courier compute a `fit_score` that starts at 100, adds 10 for every capability where the courier's skill_level is strictly greater than the zone's needed level, and subtracts 5 for every capability where the courier's skill_level is strictly less. For each zone return the courier with the highest fit_score, breaking ties by the smaller courier_id. Return a DataFrame with columns `zone_id`, `courier_id`, `fit_score`, ordered by `zone_id`.

Input data

Example rows — the live problem includes the full dataset.

couriers
courier_idcapabilityskill_level
701cold_chain5
701bike3
701cash_handling4
702cold_chain4
702bike5
zones
zone_idcapabilityneeded_level
40cold_chain4
40bike3
40cash_handling5
41cold_chain3
41bike4

Expected output

Your answer should return 2 rows with the columns zone_id, courier_id, fit_score.

Starter code (Pandas (Python))

import pandas as pd

def best_courier(couriers, zones) -> pd.DataFrame:
    # Your code here
    return couriers

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