Catch the type damage in a dirty file and flatten a nested one
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
- Load
data/customers_raw.csvwith Python'scsvmodule. Sort thesignup_datevalues as text and save the first and last tolab/types/text-sort.txt, one per line. - Parse every
signup_datewith the ISO format%Y-%m-%donly, and record how many succeed and fail inlab/types/parse.txtasparsed: Nandfailed: N. - Look at the values that failed and write in
lab/types/diagnosis.txtwhich format they use. - Flatten
data/survey.jsonintolab/types/survey.csvwith headerresponse_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.