Parse mixed date formats, and measure what guessing would cost

short · 40 min · Objective 2.3

Task

Parse every signup date in the raw customer file correctly by detecting its format, then deliberately parse the day-first dates as month-first and count how many fail, how many come out wrong, and how many survive by coincidence.

Steps

  1. Parse each signup_date in data/customers_raw.csv: values containing - as %Y-%m-%d, values containing / as %d/%m/%Y. Record parsed: N and failed: N in lab/dates/correct.txt.
  2. Parse only the / values again as %m/%d/%Y. For each, record whether it failed, produced a different date from the correct parse, or produced the same date.
  3. Record the three counts in lab/dates/guess.txt as fail: N, wrong: N and same: N.

Verify

These checks run in a POSIX shell with Python 3: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. On Windows, python3 is often a Microsoft Store placeholder that prints “Python was not found”; run alias python3=py in Git Bash first.

grep -E '^(parsed|failed): ' lab/dates/correct.txt
grep -E '^(fail|wrong|same): ' lab/dates/guess.txt

All 314 dates parse with 0 failures once the format is detected. Guessing month-first for the 30 day-first dates gives 19 failures, 9 silently wrong dates and 2 that are right only because their day and month are equal. The 19 failures are the warning; the 9 are the damage.

This is an independent study companion for CompTIA Data+ DA0-002 and is not produced by or endorsed by CompTIA.