Data Cleaning Exercises

Task: the rules
Inputs
  orders(id, customer_key) — text. id is unique.
  customers(customer_key, segment) — text. Present keys are trimmed and unique. One row has a missing key.

Rules
  customer_key: remove ASCII whitespace (space, tab, CR, LF) at both ends; an empty result is missing.
  Add segment from customers by customer_key. Keep every order.
  An order whose key is missing, or has no matching customer, gets a missing segment.
  A missing key never matches a missing key.

Output (row order does not matter)
  clean(id text, customer_key text, segment text)

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

Input: orders, rows 1 to 9 of 9
#idstringcustomer_keystring
1oz2w7missing
2of1nxC076
3okyr4·· (raw value " ")
4olohuC031
5olfmkC031
6okpom·C021⇥ (raw value " C021\t")
7ogp5lmissing
8oflukC076
9oo7yvmissing

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