Data Cleaning Exercises

Task: the rules
Input
  visits(id, region, duration_min) — text. id is unique.

Rules
  region: remove ASCII whitespace at both ends; an empty result is missing; then a missing region becomes the
  label "unknown" (the report groups by region and needs a bucket for it).
  duration_min: remove ASCII whitespace at both ends; an empty result is missing; convert to a whole number.
  A missing duration stays missing. Never fill it with 0 or any other number.
  Every duration that is present is a valid whole number.

Output (row order does not matter)
  clean(id text, region text, duration_min int64)

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

Input: visits, rows 1 to 15 of 15
#idstringregionstringduration_minstring
1vplbsEast·80· (raw value " 80 ")
2vivo8⇥East (raw value "\tEast")108
3v08ubemptymissing
4vtj0dSouth0
5v59m5·North (raw value " North")·66· (raw value " 66 ")
6vo7m1missingempty
7v67u0empty0
8vpbs2West·28· (raw value " 28 ")
9vep98West0
10vfx87·North (raw value " North")·66· (raw value " 66 ")
11vgnmc·North (raw value " North")missing
12vmoeoempty83
13vglcgSouth· (raw value "South ")104
14vmus1· (raw value " ")missing
15vwgco⇥East (raw value "\tEast")empty

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