Practical guide

Python automation for boring work: practical guide

Python automation for boring work: Start with one stable task before building a broad automation system

Comparison and decision guide

Decision pointPractical answer
Reader problemRepetitive computer work keeps taking time from higher-value work
Decision ruleUse Python when the input is consistent, and stabilize a changing UI workflow before automating it
Trade-offFile-based work is easier to keep stable, while UI automation reaches more screens but breaks more easily
Concrete testNormalize a weekly CSV and produce one checked summary file
Failure to avoidAutomating several changing websites before proving one useful workflow
First actionWrite down one repeated task, its input, output, and current time cost
Proof to checkCheck the Python documentation for the standard features and constraints you use
What the guide addsthe comparison table, CSV example, and first-script checklist

Use the table to choose the smallest useful test before deciding whether to buy anything.

Choose the smallest useful approach

ApproachUse it whenCost or limitation
A spreadsheetThis is a small, one-off job that you can check by handLittle setup; repeated pasting and range selection can introduce mistakes
Python csv moduleThe category and amount columns stay consistent across repeated filesAdd input checks once; stop when the format changes instead of guessing
Screen automationThere is no usable export and only a screen-based step remainsA changed screen can break it. It is unnecessary for this CSV example

Aggregate a three-row CSV without changing the source file

Illustrative example with fictional data. These are not customer results or a promise of time savings or income.

Input

category,amount
books,1200
software,600
books,800

Steps

  1. Create an empty working folder and save the input as weekly.csv in UTF-8. Amounts must be non-negative integers in the same unit.
  2. Save the code below as summarize.py in that folder. It uses Python 3 and its standard library; no package installation is needed.
  3. From a terminal in that folder, run python summarize.py (or python3 summarize.py where that is the installed command).
  4. Compare the new totals.csv and console total with the expected result. Use another empty folder for a repeat run: an existing totals.csv causes the script to stop rather than overwrite it.

Runnable example

import csv
from collections import defaultdict
from pathlib import Path

totals = defaultdict(int)
with Path("weekly.csv").open(encoding="utf-8-sig", newline="") as source:
    reader = csv.DictReader(source)
    if len(reader.fieldnames or []) != 2 or set(reader.fieldnames) != {"category", "amount"}:
        raise ValueError("Expected category and amount columns")
    for line, row in enumerate(reader, start=2):
        if None in row or any(value is None for value in row.values()):
            raise ValueError(f"Wrong column count on line {line}")
        category = row["category"].strip()
        raw_amount = row["amount"].strip()
        if not category or category[0] in "=+-@" or not raw_amount.isascii() or not raw_amount.isdigit():
            raise ValueError(f"Invalid category or non-negative integer amount on line {line}")
        totals[category] += int(raw_amount)

# Exclusive creation: an existing result is never overwritten.
with Path("totals.csv").open("x", encoding="utf-8", newline="") as target:
    writer = csv.writer(target)
    writer.writerow(["category", "amount"])
    writer.writerows(sorted(totals.items()))
print(f"{sum(totals.values())} total; {len(totals)} categories")

Expected output

category,amount
books,2000
software,600

Console: 2600 total; 2 categories

The books rows add up to 2,000 and software adds up to 600, giving 2,600 in total. Three input rows become two categories. Extra or missing columns, negative numbers, and decimals are rejected; they are never silently changed to zero.

Before using it on real work

  • Work on a copy and confirm that weekly.csv has not changed
  • Check both column names, encoding, and a consistent unit for every amount
  • Reconcile the input total of 2,600 with the output total of 2,600
  • Compare total setup, runtime, review, and repair time against the manual task

When to stop

Stop if columns or units keep changing, you cannot explain the totals, or you have to ignore errors to finish. Standardize the input before expanding the automation.

Next decision

Try three copies of the same format and record the results and effort. Stay with the standard library while it meets the need. Compare a paid tool only after identifying a specific missing transformation, its maintenance cost, and the total price.

No paid product is required for this example. This page does not link to a product offer.

Links and disclosure

You can try this guide without purchasing a product. This page has no product purchase link; use the reference sources to check current requirements. Ad/PR is disclosed, and the page avoids exaggerated claims or income guarantees.

Reference sources

Browse all guides