Lab: Automate a task
Write a complete script that reads a CSV of tasks, filters by status, counts by category, and prints a summary report.
- Read and parse an inline CSV using csv.DictReader
- Filter rows by a field value
- Aggregate counts by category using a dictionary
- Print a formatted summary report
This lab puts the whole Automation Thinking module together. You will write a script that reads a list of tasks from an inline CSV, filters for completed tasks, counts them by category, and prints a clean summary report.
No new syntax here. The goal is to build the habit of combining the pieces you already know into something useful.
The scenario
Your team tracks tasks in a CSV file. Each row has a task name, a category, and a status
(done or pending). Management wants a daily report: how many tasks are done per
category?
Here is the data you are working with:
task,category,status
Write tests,engineering,done
Deploy to staging,engineering,done
Update docs,documentation,pending
Write changelog,documentation,done
Review PRs,engineering,done
Update README,documentation,done
Fix login bug,engineering,pending
Write user guide,documentation,pendingCheckpoint 1 — parse the CSV
Start by reading the data and printing every row as a dictionary:
Each row is a dictionary like {'task': 'Write tests', 'category': 'engineering', 'status': 'done'}.
That is the raw material for everything that follows.
Checkpoint 2 — filter for completed tasks
Add a condition to keep only rows where status == 'done':
Checkpoint 3 — count by category
Use a dictionary to accumulate counts. For each completed task, increment the counter for its category:
counts.get(cat, 0) returns the current count for cat, or 0 if the key does not
exist yet. This is the idiomatic Python way to build a counter without a key-exists
check.
Checkpoint 4 — the complete script
Put it all together into a main() function with clear output:
Notice the structure: separate functions for loading, processing, and reporting.
This makes each step easy to test and easy to swap out. If the data source changes
from an inline string to a real file, you only touch load_tasks().
Extend it yourself
Once you have the script running, try these changes:
- Add a count of pending tasks per category alongside the done count.
- Add a
--categoryfilter so the report shows only one category. - Change
load_tasks()to accept a file path and read from a real CSV file on disk.
The third extension is the bridge to real automation: the script's logic stays the same; only the data source changes.
Building a CLI script
Structure a Python script with a main() function, argparse for flags, and the if __name__ == '__main__' guard.
Structured data concepts
CSV, JSON, and plain text each have a job. Knowing which format fits which problem — and what parsing actually means — is where data work starts.