Excel is still the accountant’s main tool, and it should be. Python earns its place when a job is too big, too repetitive or too messy for a workbook: thirty branch files every month, a ledger longer than Excel’s 1,048,576 rows, or an audit test that must run on every transaction and be repeated next year exactly the same way.
You do not need to become a programmer. You need enough Python to read a short script, run it on a copy, and check its answer. AI can write much of the code once you can describe the job clearly. This guide shows where Python pays off, how to start for free, and two scripts we ran on made-up data, with their real output.
Where Python pays off in accounting
| Job | What Python does | Why not just Excel |
|---|---|---|
| Combining files: branch sales, 12 months, bank statements | Reads every file in a folder, cleans each one the same way, stacks them | No copy and paste, and the same steps every month |
| Very large ledgers | Reads millions of rows and summarises them | A worksheet stops at 1,048,576 rows |
| Whole-population tests | Duplicate payments, gaps in cheque or voucher numbers, weekend postings, round amounts | The test is written down and can be rerun next year |
| Matching | Bank to ledger, intercompany balances, supplier statements, with rules for dates and references | Many-to-one matches are slow by hand |
| Monthly reports | Builds the same summary workbook from fresh data | One command instead of an afternoon |
If your company has a paid Microsoft 365 licence, Python in Excel (the =PY function) runs Python inside a workbook. It needs an eligible paid plan and runs in Microsoft’s cloud, so check with IT first. Everything on this page works with free tools.
Start free, without installing anything
- Google Colab (colab.research.google.com) runs Python in your browser with a Google account. Choose New notebook, then type code in a cell and press Shift+Enter. pandas, the library for tables, is already there.
- Upload a file with the folder icon on the left. Uploads go to Google’s servers, so use made-up or published data only.
- When you are ready to work offline, install Python from python.org (tick “Add python.exe to PATH”), then type
pip install pandas openpyxlin Command Prompt. On an office computer, ask IT before installing anything.
Excel to pandas: the words you need first
Most of what an accountant does in Excel has a one-line equivalent in pandas, the Python library for tables. This is the whole vocabulary for your first month:
| In Excel | In pandas |
|---|---|
| Open a workbook | df = pd.read_excel("file.xlsx") |
| Filter rows | df[df["Amount (Tk)"] > 100000] |
| A formula column | df["VAT"] = df["Amount (Tk)"] * 0.15 |
| SUMIFS or a PivotTable | df.groupby("Supplier name")["Amount (Tk)"].sum() or df.pivot_table(...) |
| VLOOKUP or XLOOKUP | df.merge(suppliers, on="Supplier ID", how="left") |
| Sort | df.sort_values("Payment date") |
| Remove duplicates | df.drop_duplicates() |
| Save as | df.to_excel("out.xlsx", index=False) |
Script 1: payments by supplier and month
Practice file: the made-up company’s 10,000 supplier payments from our duplicate payments test (download it on that page). Put the script and the file in the same folder, or upload both to Colab.
import pandas as pd
df = pd.read_excel("padma-traders-payments-2025-26.xlsx", sheet_name="Payments")
df["Month"] = df["Payment date"].dt.strftime("%Y-%m")
summary = df.pivot_table(index="Supplier name", columns="Month", values="Amount (Tk)",
aggfunc="sum", fill_value=0, margins=True, margins_name="Total")
summary.to_excel("payments-by-supplier-and-month.xlsx")
print("Rows read:", len(df))
print("Total paid (Tk):", f"{df['Amount (Tk)'].sum():,}")
Rows read: 10000 Total paid (Tk): 738,335,365
Python groups digits in thousands: 738,335,365 is Tk 73,83,35,365. The workbook it saves has one row per supplier, one column per month, and totals.
Script 2: find duplicate payments
The same file hides 25 invoices paid twice, worth Tk 17,21,078: exact repeats, invoice numbers typed differently (CC/185 and CC-185), the same supplier set up twice under two IDs, and amounts with two digits swapped. It also has decoys: monthly rent and a software fee, the same supplier and amount every month, which are not duplicates.
The trick is the key. The supplier’s bank account catches a supplier set up twice; the invoice number with its dashes, slashes, spaces and leading zeros removed catches the typing differences; and leaving the amount out of the key catches swapped digits.
import pandas as pd
df = pd.read_excel("padma-traders-payments-2025-26.xlsx", sheet_name="Payments",
dtype={"Supplier bank a/c (last 4)": str, "Invoice no.": str})
# The same bank account + the same invoice number (ignoring "-", "/", spaces and leading zeros)
df["Invoice key"] = (df["Invoice no."].str.upper()
.str.replace(r"[^A-Z0-9]", "", regex=True)
.str.lstrip("0"))
df["Key"] = df["Supplier bank a/c (last 4)"] + "|" + df["Invoice key"]
df = df.sort_values(["Key", "Payment date", "Payment ID"])
repeats = df[df.duplicated("Key", keep="first")] # the second (and any later) payment
suspects = df[df["Key"].isin(repeats["Key"])] # both sides of each pair, for review
suspects.to_excel("possible-duplicates.xlsx", index=False)
print("Payments that repeat an earlier invoice:", len(repeats))
print("Amount at risk (Tk):", f"{repeats['Amount (Tk)'].sum():,}")
Payments that repeat an earlier invoice: 25 Amount at risk (Tk): 1,721,078
All 25 planted pairs, Tk 17,21,078, and no false alarms: we checked the 50 payments it listed against the answer key, pair by pair. The rent and software decoys were not flagged, because each month has its own invoice number.
Let AI write your next script
In our Python without coding test, two free AIs wrote scripts for twelve messy files; both crashed, and both “fixed” versions reported totals of zero. The lesson is not to avoid AI, but to brief it properly and check what comes back.
- Show it the data, not a description. Paste the column names and five made-up rows of each different kind of file.
- Say exactly what you want out: which columns, which totals, which file name.
- Ask it to stop with a clear message when a column or date cannot be read, instead of guessing.
- Ask for check lines: rows read and the grand total.
- Read it, then run it on a copy. Ask the AI to explain any line you do not understand.
I am an accountant learning Python. Write a short pandas script that reads every .xlsx file in a folder called "Bank statements", stacks them into one table, and saves "all-statements.xlsx". Columns in each file: Date | Description | Cheque no. | Debit | Credit | Balance. Here are 5 made-up rows: [paste] Rules: dates are day-first; Debit and Credit may be blank; skip any row where Date is blank. If a file is missing a column, stop and print the file name and the missing column. Do not guess. At the end, print the number of rows read and the totals of Debit and Credit. Explain each line in a comment, in simple English.
A four-week plan
| Week | Do | Free resource |
|---|---|---|
| 1 | Variables, lists, loops and functions, an hour a day | Kaggle Learn: Python, or the official Python tutorial (chapters 3 to 5) |
| 2 | Read, filter, group and merge tables | Kaggle Learn: Pandas; “10 minutes to pandas” |
| 3 | Run the two scripts above, then change them: totals by payment method, payments over Tk 5 lakh, suppliers paid on a Friday | The practice file on our duplicate payments test |
| 4 | One job of your own, on made-up data, with a written note of the steps and the check total | AI as your tutor (prompt above) |
Watch out
- Company data and IT rules come first. Do not install software or move office files to personal tools without permission.
- Never edit the only copy. Scripts read from a copy and write to a new file.
- Keep the script with the output. Next month, or next year’s auditor, can see exactly what was done.
- Numbers stored as text (“1,25,000”) and dates read the wrong way round are the commonest silent errors. Check totals and the first and last dates every time.
Practise on this site
Sources
- The Python Tutorial (opens in a new tab)
- 10 minutes to pandas (opens in a new tab)
- Kaggle Learn: free courses (Python, Pandas) (opens in a new tab)
- Colab: frequently asked questions (opens in a new tab)
- Excel specifications and limits (opens in a new tab)
- Python in Excel availability (opens in a new tab)