Put an analysis under version control and watch it change

short · 35 min · Objective 1.4

Task

Write a small analysis script, commit it to a Git repository, change what it calculates, commit again, and use the history to show exactly what changed and when.

Steps

  1. Create lab/vc, run git init there, and write lab/vc/count.py, which prints the number of orders in data/orders.csv.
  2. Commit it with the message count all orders.
  3. Change the script so it counts only orders with a positive quantity, run it, and save the output to lab/vc/output.txt. Commit with the message exclude impossible quantities.
  4. Save git log --oneline to lab/vc/history.txt and git diff HEAD~1 HEAD to lab/vc/change.diff.

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.

wc -l < lab/vc/history.txt
grep -c 'exclude impossible quantities' lab/vc/history.txt
grep -c '^[+]' lab/vc/change.diff
cat lab/vc/output.txt

Two commits in the history, the second named as the change, a diff showing the lines that changed, and an output of 1997 -- the 2000 orders less the three with negative quantities. Anyone who asks why the count dropped by three can read the answer in the history.

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