AnalystPath

Last Crate Loaded on the Delivery Van

PandasMediumMid level~10 min

Problem

You are given a DataFrame `loadingline` loaded from `loadingline.csv` with columns `crate_id`, `label`, `mass_kg`, and `load_order`. Crates are loaded onto a delivery van one at a time in increasing `load_order` (values are unique).

The van can carry at most **1000 kg**. Loading proceeds in `load_order`; as soon as adding the next crate would push the running total above 1000 kg, loading stops and no further crate is loaded. Return a one-row DataFrame with a single column `label` holding the label of the last crate that actually makes it onto the van.

Input data

Example rows — the live problem includes the full dataset.

loadingline
crate_idlabelmass_kgload_order
5Ceramics2501
3Books3502
6Glassware4003
2Linens2004
4Cutlery505

Expected output

Your answer should return 1 row with the columns label.

Starter code (Pandas (Python))

import pandas as pd

def last_crate(loadingline) -> pd.DataFrame:
    # Your code here
    return loadingline

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