
π This article includes 3 downloadable practice files β
In this article
The whole course in one script: drop next month’s CSV into monthly/, run, and the report is ready.
The shape of a good pipeline
def load(folder): # 1. read every file, remember where each row came from
frames = [pd.read_csv(f).assign(source=f.name) for f in sorted(folder.glob("sales-*.csv"))]
return pd.concat(frames, ignore_index=True)
def enrich(df): # 2. join products and customers, add amount, GST, month
...
df = enrich(load(HERE / "monthly"))
kpi = ... # 3. summarise
with pd.ExcelWriter(out / "monthly-report.xlsx") as xw: # 4. write
kpi.to_frame("value").to_excel(xw, sheet_name="KPIs")
by_month.to_excel(xw, sheet_name="By month")
Small functions with one job each are easy to test and easy to change: a new data source only touches load.
Make it production-ready
- Logging (lesson 3): the row count per file catches a missing or half-downloaded month.
- Paths from HERE (lesson 1) so Task Scheduler can run it.
- Options (lesson 9):
--monthto rebuild a past report. - Formatting (lesson 7): open the written file with openpyxl afterwards to add styles and a chart.
Next: read straight from a database with pd.read_sql (see the SQL Intermediate Course) instead of CSV exports.
Practice
Unzip the practice data into a folder, put this lesson’s script in the same folder and run it (python pyi-NN.py). Compare with the expected output file. Then change one thing (a filter, a column, a format) and predict the new output before you run it.
π Practice files for this article
β¬ Download all 3 files (ZIP Β· 5 KB)
- πLesson 10 scriptThe complete script from this lesson, ready to run.β¬ PY Β· 2 KB
- πExpected outputWhat the script printed when we ran it, to compare with yours.β¬ TXT Β· 477 B
- ποΈPractice data (zip)sales.csv (120 invoices, 2 deliberately broken rows), customers.csv, products.json, statement.txt, rates.json and 3 monthly CSVs.β¬ ZIP Β· 4 KB
Free to use for learning. Files with macros (.bas) are plain text β import them with Alt+F11 β File β Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.