Last Crate Loaded on the Delivery Van
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.
| crate_id | label | mass_kg | load_order |
|---|---|---|---|
| 5 | Ceramics | 250 | 1 |
| 3 | Books | 350 | 2 |
| 6 | Glassware | 400 | 3 |
| 2 | Linens | 200 | 4 |
| 4 | Cutlery | 50 | 5 |
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 loadinglineSolve 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