CSV and JSONL — the two formats AI moves data in — step 9 of 9
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Last drill. Convert a CSV into JSONL.
Write a function csv_to_jsonl(csv_path, jsonl_path) that:
- Opens
csv_pathwithcsv.DictReader(remembernewline=""). - For each row, converts the
scorecolumn from string to int. - Writes one JSON object per line to
jsonl_path. - Returns the number of rows written.
The starter writes a tiny CSV, calls your function, then reads the
JSONL back and prints each parsed record's name and score.
Expected output:
3
alex 82
sam 91
jordan 77
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Last drill. Convert a CSV into JSONL.
Write a function csv_to_jsonl(csv_path, jsonl_path) that:
- Opens
csv_pathwithcsv.DictReader(remembernewline=""). - For each row, converts the
scorecolumn from string to int. - Writes one JSON object per line to
jsonl_path. - Returns the number of rows written.
The starter writes a tiny CSV, calls your function, then reads the
JSONL back and prints each parsed record's name and score.
Expected output:
3
alex 82
sam 91
jordan 77
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.