Filling a Shipping Container
Problem
A 600-liter shipping container is loaded from the `cargo` DataFrame, where each row is one parcel of a `cargo_class` (`express` or `standard`) occupying some `volume` in liters. Columns: `parcel_id`, `cargo_class`, `region`, `volume`.
Fill the container to hold as many parcels as possible. First pack whole copies of the entire set of **express** parcels repeatedly until no full set fits, then use whatever volume remains to pack whole copies of the entire set of **standard** parcels. A 'copy' means loading one of every parcel of that class.
Return `cargo_class` and `parcel_count` (total parcels loaded) with the `express` row first, then the `standard` row.
Input data
Example rows — the live problem includes the full dataset.
| parcel_id | cargo_class | region | volume |
|---|---|---|---|
| 1 | express | North | 60.0 |
| 2 | express | South | 40.0 |
| 3 | standard | East | 20.0 |
| 4 | standard | West | 30.0 |
Expected output
Your answer should return 2 rows with the columns cargo_class, parcel_count.
Starter code (Pandas (Python))
import pandas as pd
def fill_container(cargo) -> pd.DataFrame:
# Your code here
return cargoSolve 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