What is Python actually used for?
One example: every Monday, an executive assistant pulls the register export, deletes the empty rows and copies the totals into a report. A Python program of about twenty lines does this work for her, the same way every week: it ignores the empty rows, adds up by product and writes the report. Tested on a sample export: "2 products in the report". That is the level aimed for at the end of Python Fundamentals.
- Save time at the office: merge CSV files, rename documents in bulk, clean up an export
- Move toward data: Python is the core tool for data analysis and machine learning
- Build applications: Python runs the server side of websites and APIs
- Build with AI: most generative AI tools and agents are driven with Python
import csv
totals = {}
with open("register_export.csv", encoding="utf-8") as f:
for row in csv.DictReader(f, delimiter=";"):
if not row["product"].strip():
continue # empty row: skip it
amount = float(row["amount"].replace(",", "."))
totals[row["product"]] = totals.get(row["product"], 0) + amount
with open("weekly_report.csv", "w", encoding="utf-8", newline="") as f:
output = csv.writer(f, delimiter=";")
output.writerow(["product", "total"])
for product, total in sorted(totals.items()):
output.writerow([product, f"{total:.2f}"])
print(len(totals), "products in the report")
