Data Cleaning Exercises

Exercise · intermediate · 20 min

Parse dates by declared locale

03/04/2026 is March 4th in the US and 3 April in the UK. Parse slash dates only when the row says which convention it uses.

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

Rules
  Accept raw_date when it is:
    - an ISO date YYYY-MM-DD (any locale, including missing), or
    - a slash date D/M/YYYY or M/D/YYYY (1–2 digit day and month) AND locale is
        en-US → month first, or en-GB → day first.
  Quarantine with reason:
    invalid_date      raw_date is missing, or a slash date with a declared locale names a day that does not exist (31/02/2026)
    ambiguous_format  anything else, including a slash date whose locale is missing or not en-US/en-GB

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

The data

events · 8 rows

idraw_datelocale
evvsoj04/08/2025en-GB
evkcwt02/12/2025en-GB
evsig02025-06-05en-US
evrwhn6/20/2025missing
evsr7005/12/2025en-GB
eva3552026/04/03en-GB
evnf0z13/13/2026en-GB
eve73401/03/2026en-US

What you practise

  • dates
  • locales
  • quarantine

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.