Count Bottles and Cans Across Pallets
Problem
You are given two DataFrames. `pallet` has columns `pallet_id`, `crate_id`, `bottle_qty`, `can_qty`; its `crate_id` may be missing when a pallet carries no crate. `crate` has columns `crate_id`, `bottle_qty`, `can_qty`.
For every pallet, its contribution is its own quantities plus the quantities of the crate it references (zero when it has no crate). Return the grand total bottles and cans across all pallets as a single row. Output columns: `bottle_qty`, `can_qty`.
Input data
Example rows — the live problem includes the full dataset.
| pallet_id | crate_id | bottle_qty | can_qty |
|---|---|---|---|
| 1 | 100 | 5 | 2 |
| 2 | 3 | 4 | |
| 3 | 101 | 0 | 1 |
| crate_id | bottle_qty | can_qty |
|---|---|---|
| 100 | 10 | 20 |
| 101 | 7 | 0 |
Expected output
Your answer should return 1 row with the columns bottle_qty, can_qty.
Starter code (Pandas (Python))
import pandas as pd
def count_bottles_and_cans(pallet, crate) -> pd.DataFrame:
# Your code here
return palletSolve 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