AnalystPath

Pallets With a Well-Formed Tracking Code

PandasEasyJunior level~10 min

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.

pallets
pallet_idzone_labelnote
1Dock NorthReceived pallet PL2048/917 this morning
2Cold StoreTagged PL0007/300 awaiting count
3Dock SouthStamp PL2048/9175 was misprinted
4MezzanineNo tracking code recorded
5Bulk AisleScan 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 pallets

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