Parse dates by declared locale · Python (pandas)
Task: the 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)Tab inserts spaces. Press Escape, then Tab, to move focus out of the editor.
| # | idstring | raw_datestring | localestring |
|---|---|---|---|
| 1 | evvsoj | 04/08/2025 | en-GB |
| 2 | evkcwt | 02/12/2025 | en-GB |
| 3 | evsig0 | 2025-06-05 | en-US |
| 4 | evrwhn | 6/20/2025 | missing |
| 5 | evsr70 | 05/12/2025 | en-GB |
| 6 | eva355 | 2026/04/03 | en-GB |
| 7 | evnf0z | 13/13/2026 | en-GB |
| 8 | eve734 | 01/03/2026 | en-US |
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.