Pallets With a Well-Formed Tracking Code
Problem
You are given a DataFrame `pallets` (loaded from `pallets.csv`) with columns `pallet_id`, `zone_label`, and `note`. Each row describes a storage pallet and a free-text receiving note.
A warehouse stamps a tracking code on a pallet in the format `PL` followed by exactly four digits, then a forward slash, then exactly three digits -- for example `PL2048/917`. A code with too few or too many digits in either group is invalid, and the three-digit group must not be immediately followed by another digit.
Return every pallet whose `note` contains a well-formed tracking code. Return `pallet_id`, `zone_label`, and `note`, sorted by `pallet_id` ascending.
Input data
Example rows — the live problem includes the full dataset.
| pallet_id | zone_label | note |
|---|---|---|
| 1 | Dock North | Received pallet PL2048/917 this morning |
| 2 | Cold Store | Tagged PL0007/300 awaiting count |
| 3 | Dock South | Stamp PL2048/9175 was misprinted |
| 4 | Mezzanine | No tracking code recorded |
| 5 | Bulk Aisle | Scan PL6612/041 then shelve |
Expected output
Your answer should return 3 rows with the columns pallet_id, zone_label, note.
Starter code (Pandas (Python))
import pandas as pd
def well_formed_pallets(pallets) -> pd.DataFrame:
# Your code here
return palletsSolve 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