AnalystPath

Filling a Shipping Container

PandasHardSenior level~10 min

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.

cargo
parcel_idcargo_classregionvolume
1expressNorth60.0
2expressSouth40.0
3standardEast20.0
4standardWest30.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 cargo

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