Tutorials
Python for Treasury Work
Short, practical Python lessons built around the daily work of a local treasury office: receipts, collections, penalties, reports and audit trails. Every example uses made-up data, runs as written, and shows the output it really prints. I am learning alongside you, so the lessons grow from simple scripts to the tools I use in building software.
Where to begin. New to Python? Start with Lesson 0. It shows how to install Python, run a script, and fix the errors almost everyone meets on the first day. Then take the lessons in order; each one builds on the one before.
Our promise. Every lesson is checked before it goes live: the code is run, the output you see is what it really prints, the facts and laws are checked against sources, and the page is reviewed on phone and computer. Each lesson shows the month it was last checked.
Getting started: install Python and run your first script
Install Python on Windows or Mac, open the command line, and run a script, with fixes for the usual first errors.
Start the lesson →Add up a day's collections from a CSV file
Read the day's official receipts from a spreadsheet export and total them per fund, to the centavo.
Start the lesson →Check an official receipt series for gaps and duplicates
Compare the receipts recorded today with the booklet issued, and flag missing, repeated or stray numbers.
Start the lesson →Compute real property tax penalties with Decimal
See why floats are unsafe for money, then compute 2% monthly penalties with a 36-month cap, rounded correctly.
Start the lesson →Build a simple RCD summary with pandas
Group collections by collector and fund, list the receipts used, and match collections against deposits.
Start the lesson →Make a tamper-evident log with HMAC
Seal each log entry with a keyed hash chained to the one before it, so any later edit or deletion shows.
Start the lesson →Civil Service Exam Vocabulary
Ten words at a time for the Career Service Examination (Professional and Subprofessional). The exam's verbal part tests vocabulary, analogies and how words are used in a sentence, so each word comes with a plain meaning, an example from government work, words that mean the same and the opposite, and practice questions in the exam's style.
Governance, law and public administration
Ten words you meet in memos, audit reports and office orders: acquiesce, ad hoc, anomaly, arbitrary, ascertain, assiduous, autonomous, bureaucracy, cognizant and compliance.
Start the module →Ethics, integrity and professional conduct
Ten words about honesty and good conduct in public office: candor, capricious, collusion, discretionary, efficacy, egregious, incorruptible, integrity, prudent and transparent.
Start the module →Analysis, planning and operations
Ten words for reports, audits and planning: aggregate, corroborate, disseminate, empirical, feasible, fiduciary, mitigate, pragmatic, scrutinize and substantiate.
Start the module →Public finance and local government
Ten words from budgets, taxes and local councils: amortization, appropriation, biennial, cadastral, censure, codify, concurrence, demographics, disbursement and levy.
Start the module →Words to know
- Script
- A text file of Python code, saved with the .py ending, that you run from start to finish.
- Variable
- A name that holds a value, like receipts = 10. You can change it later.
- Loop
- Code that repeats for each item, written with for. It is how a script goes through every row of a file.
- Function
- A named set of steps you can reuse, written with def. You give it inputs and it gives back a result.
- Module
- A file of ready-made code you bring in with import, such as csv or decimal.
- CSV
- Comma-separated values: a plain text table, one row per line, that Excel and most systems can export.
- List
- An ordered collection, written with square brackets: [7650101, 7650102].
- Dictionary
- Pairs of keys and values, written with braces: {"General Fund": 21986.15}. You look a value up by its key.
- Set
- A collection with no repeats and no order. Good for comparing what you have with what you expected.
- Decimal
- A number type that keeps peso amounts exact, so centavos never drift.
- f-string
- Text that starts with f and fills in values inside braces: f"Total: {total}".
- DataFrame
- The table that the pandas library works with: rows and named columns, like a sheet in Excel.
- Library
- A collection of modules someone else wrote, such as pandas. Some come with Python; others you install.
- pip
- Python's installer for extra libraries: pip install pandas.
- Hash
- A short fingerprint of some data. Change one character and the fingerprint changes completely.
- HMAC
- A hash made with a secret key. Only someone with the key can make a matching one.
New lessons are added regularly. All names, receipt numbers and amounts in the examples are made up.