Data Cleaning Exercises

Exercise · beginner · 10 min

Label unknown categories, keep missing numbers missing

A report needs every visit in a region bucket, so a missing region becomes "unknown". A missing duration is different: filling it with 0 would drag the average down.

The rules

These rules decide what a correct result is. Your answer is checked on this dataset and on hidden datasets that follow the same 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)

The data

visits · 15 rows, first 12 shown

idregionduration_min
vplbsEast·80·
vivo8·East108
v08ubemptymissing
vtj0dSouth0
v59m5·North·66·
vo7m1missingempty
v67u0empty0
vpbs2West·28·
vep98West0
vfx87·North·66·
vgnmc·Northmissing
vmoeoempty83

What you practise

  • missing values
  • filling
  • blank text
  • type conversion

Your answer is also checked on hidden datasets generated from the same rules.

Download this dataset (CSV) with its data dictionary

Sign in to bookmark this and keep private notes.