Data Cleaning Exercises

Task: the rules
Input
  inventory(id, sku, quantity, unit_price, country) — text. id is unique; sku is always present.

Normalize
  country: remove ASCII whitespace at both ends, then uppercase.

Quarantine each invalid row with the FIRST failing reason, checked in this order:
  1. missing_quantity        quantity is missing
  2. bad_quantity            quantity is not a whole number: optional "-" then digits only
  3. quantity_out_of_range   quantity is less than 1 or greater than 500
  4. bad_price               unit_price is missing, or is not: optional "-", digits, optionally "." and 1–2 digits
  5. price_out_of_range      unit_price is zero or negative
  6. bad_country             country is not one of US, CA, MX (a missing country is also bad_country)

Outputs (row order does not matter)
  clean(id text, sku text, quantity int64, unit_price decimal(10,2), country text)
  exceptions(id text, reason text)

Tab inserts spaces. Press Escape, then Tab, to move focus out of the editor.

Input: inventory, rows 1 to 21 of 21
#idstringskustringquantitystringunit_pricestringcountrystring
1invybqzSKU-62521760.28·CA (raw value " CA")
2invf1geSKU-7738501580.05MX
3invoi41SKU-000312-1.00USA
4invereeSKU-519123572.57·CA (raw value " CA")
5inv29z8SKU-000100.00UK
6invvnhmSKU-4924434524.17US
7invkmmsSKU-44967.5573.38CA
8inveec2SKU-684710us
9invezdpSKU-0936436956.62US
10invgt2uSKU-92594401,200.00MX
11inv4nh6SKU-6643721,200.00MX
12invi6w4SKU-0002missingabcmissing
13invqlouSKU-754347012.5mx⇥ (raw value "mx\t")
14inv04arSKU-1830empty969.00US
15invqmktSKU-6302349.999MX
16invkeprSKU-9281emptymissingCA
17invbl5xSKU-4147500missingUSA
18inv6qmzSKU-41693880empty
19invympzSKU-6955empty9.999mx⇥ (raw value "mx\t")
20invxr2kSKU-4668730.99US
21inv2c6vSKU-0917171-1.00USA

Run preview · in your browser, not a grade

Loading the preview runtime…

Check answer · graded on an isolated server, including hidden datasets

Your code runs in a locked-down machine with no network, on the visible data and on hidden datasets that follow the same rules.

Learn from this exercise

A worked solution becomes available after your first check or once you've used every hint.

AI tutor · may be wrong; the grader decides

Python · Python 3.14 · pandas 3.0.2Preview runtime loadingNot saved yet · sign in to save to your account