AnalystPath

Which Veteran and Rookie Pilots Fit the Payroll

PandasHardSenior level~10 min

Problem

You are given a DataFrame `pilots` with columns `pilot_id`, `rank`, and `wage`. `pilot_id` uniquely identifies each pilot, `rank` is either `'Veteran'` or `'Rookie'`, and `wage` is the pilot's annual wage.

An airline has a hiring budget of `50000`. It first hires `Veteran` pilots, cheapest wage first (ties broken by smaller `pilot_id`), taking each while the running total of veteran wages stays within budget. With the leftover budget it then hires `Rookie` pilots under the same cheapest-first rule. Return the `pilot_id` of every pilot actually hired, in any order, in one column `pilot_id`.

Input data

Example rows — the live problem includes the full dataset.

pilots
pilot_idrankwage
1Veteran20000
2Veteran25000
3Veteran30000
4Rookie4000
5Rookie3000

Expected output

Your answer should return 3 rows with the columns pilot_id.

Starter code (Pandas (Python))

import pandas as pd

def which_veteran_and_rookie_pilots_fit_the_payroll(pilots) -> pd.DataFrame:
    # Your code here
    return pilots

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