Lab 2 of 2 Members
Lab 2: From a messy CSV to a JSON report
Read a CSV export with a broken row, skip the bad data, total the rest, and save the result as a JSON report, using only Python's built-in csv and json modules.
Do this lab after reading “Files, CSV and JSON” in the lesson. It uses with open(...), csv.DictReader,
float(), try/except and json.dump, all explained there.
The finance team exports orders from the shop as orders.csv every week. They want a small JSON report back: how
many orders, and the total amount. The export isn’t perfect, though. One amount is N/A, and if you add it up as is,
the script crashes.
Every task is one small step. Stuck? Press Cheatsheet under a task to see the syntax on different data, copy the
pattern, swap in the lab’s file and fields, and press Run. orders.csv sits next to main.py; click its tab to
look inside. Files your script writes show up as new tabs after a run.
When you’re done, go back to the lesson tab for the last part: running Python and pandas on your own computer.
This lab is for members
Write and run real Python right in your browser, with tasks that check themselves. Members unlock every lab, lesson, and module, plus the private community.
7-day free trial · Cancel any time