Join orders to customers without matching blanks · Python (pandas)
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.
| # | idstring | customer_keystring |
|---|---|---|
| 1 | oz2w7 | missing |
| 2 | of1nx | C076 |
| 3 | okyr4 | ·· (raw value " ") |
| 4 | olohu | C031 |
| 5 | olfmk | C031 |
| 6 | okpom | ·C021⇥ (raw value " C021\t") |
| 7 | ogp5l | missing |
| 8 | ofluk | C076 |
| 9 | oo7yv | missing |
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.