Catch the type damage in a dirty file and flatten a nested one

short · 40 min · Objective 1.1

Task

Read the raw customer file and find what goes wrong when its dates are treated as text, parse them properly and count what fails, then flatten the nested survey export into an ordinary table.

Steps

  1. Load data/customers_raw.csv with Python's csv module. Sort the signup_date values as text and save the first and last to lab/types/text-sort.txt, one per line.
  2. Parse every signup_date with the ISO format %Y-%m-%d only, and record how many succeed and fail in lab/types/parse.txt as parsed: N and failed: N.
  3. Look at the values that failed and write in lab/types/diagnosis.txt which format they use.
  4. Flatten data/survey.json into lab/types/survey.csv with header response_id,submitted,age_band,region,satisfaction,recommend,comment, one row per response.

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.

cat lab/types/text-sort.txt
grep -E '^(parsed|failed): [0-9]+$' lab/types/parse.txt
python3 -c "import csv; r=list(csv.DictReader(open('lab/types/survey.csv', encoding='utf-8'))); print(len(r), 'rows,', len(r[0]), 'columns')"

Sorted as text, the "earliest" signup is 04/02/2022 and the "latest" 31/01/2023, though the real dates run to October 2025. The ISO parse succeeds 284 times and fails 30 -- the day-first dates -- and the flattened survey has 200 rows and 7 columns.

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