Data Cleaning Exercises

Task: the rules
Inputs
  payments(id, account, amount_cents) — text. id is unique. amount_cents is always a valid whole number (refunds are negative).
  accounts(account, name) — text. Accounts are trimmed and unique, never missing.

Rules
  account: remove ASCII whitespace at both ends; an empty result is missing.
  Quarantine each invalid payment with the FIRST failing reason:
    1. missing_account   account is missing
    2. unknown_account   account has no matching row in accounts
  Valid payments get the account's name.

Outputs (row order does not matter)
  clean(id text, account text, name text, amount_cents int64)
  exceptions(id text, reason text)

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

Input: payments, rows 1 to 10 of 10
#idstringaccountstringamount_centsstring
1pay59hn99951974
2payij5o457923
3payfhun777641
4paym2n8missing72752
5paywa3o999-1746
6pay7u1w·7· (raw value " 7 ")-1489
7pay77t1999-3521
8payacbh4880852
9payngmn787639
10payfkj9999-461

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