Data Cleaning Exercises

Exercise · beginner · 15 min

Map channels with an approved dictionary

Support tickets name the same channel a dozen ways. Map them with the approved dictionary only, and quarantine anything the dictionary doesn't cover instead of guessing.

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
  tickets(id, channel) — text. id is unique. channel may be missing.

Rules
  channel: remove ASCII whitespace (space, tab, CR, LF) at both ends, then lowercase; an empty result is missing.
  Map channel with this approved dictionary (left → right) and nothing else:
    email → email      e-mail → email
    phone → phone      telephone → phone
    chat → chat        web chat → chat      webchat → chat
  Quarantine to exceptions with reason:
    missing_channel    channel is missing
    unmapped_channel   channel is present but not in the dictionary (never guess a mapping)

Outputs (row order does not matter)
  clean(id text, channel text)
  exceptions(id text, reason text)

The data

tickets · 13 rows, first 12 shown

idchannel
tx6ldempty
t1bmfPhone·
t6s3mTELEPHONE
t7f5e·email
tsvpjWeb Chat
ta4ene mail
tacytWebChat·
t95p3··
t9ulvchat
t9k3me-mail·
tzj97missing
t22bjTELEPHONE

What you practise

  • mappings
  • controlled vocabulary
  • quarantine
  • trimming

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.