Data Cleaning Exercises

Task: the rules
Input
  members(member_id, postcode, opted_in) — text. member_id is unique and always present.

Rules
  member_id and postcode are identifiers: keep them as text exactly as given, except that postcode has
  ASCII whitespace removed at both ends. Never convert them to numbers (00123 must stay 00123).
  opted_in: remove ASCII whitespace at both ends, then lowercase, then:
    y, yes, true, 1   → true
    n, no, false, 0   → false
  Quarantine with reason bad_flag when opted_in is missing or anything else (a missing answer is not "no").

Outputs (row order does not matter)
  clean(member_id text, postcode text, opted_in bool)
  exceptions(member_id text, reason text)

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

Input: members, rows 1 to 17 of 17
#member_idstringpostcodestringopted_instring
100841798506· (raw value "98506 ")true
2000002·02139· (raw value " 02139 ")maybe
3002939missing0
4015246·51389 (raw value " 51389")y
5077927·08222 (raw value " 08222")N
609280330041true
7085051⇥12134· (raw value "\t12134 ")N
800000100501yes
9004197·52402 (raw value " 52402")true
10016386⇥46532· (raw value "\t46532 ")no
11016648·20460 (raw value " 20460")yes
12078978missingno
1306284482606· (raw value "82606 ")y
14040367⇥71788· (raw value "\t71788 ")No· (raw value "No ")
1505427278568· (raw value "78568 ")YES
16022910⇥11785 (raw value "\t11785")YES
1707697160216· (raw value "60216 ")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.

AI tutor · may be wrong; the grader decides

SQL · DuckDB 1.5.1Preview runtime loadingNot saved yet · sign in to save to your account