Python for Finance, With AI Writing Most of It
The fair question in 2026 is whether a finance person should still learn Python when a model will write it for you.
My answer is yes, and the reason has changed. You are no longer learning to write it. You are learning to read it well enough to know when the thing you were handed is wrong, and to run it without breaking something.
That is a much smaller job than it was five years ago. A weekend instead of a semester.
This covers the setup, the one library that matters, how I write Python now, and what to do if you are arriving here from VBA or R.
What Python does that Excel does not
Four things, and if none of them are your problem then you do not need this yet.
- Row counts past a million. Excel stops at 1,048,576 and gets miserable well before that. pandas handles ten million on a laptop without complaint.
- The same job, 200 times. Loop over 200 files, 200 entities, 200 scenarios. Excel makes you copy a sheet.
- Anything that has to run without you. A script on a schedule beats a workbook someone has to open.
- Statistics past a trendline. Regression with diagnostics, time series, clustering. Excel technically does some of this and you will hate it.
Everything else, and I mean most of finance, is faster in Excel or Power Query. If your job is a 40,000-row monthly file that needs cleaning, Power Query is the better tool and I would not touch Python for it.
Setup, about twenty minutes
Install Python from python.org, tick the box that says add to PATH, and install VS Code. Then one command in the terminal:
pip install pandas numpy matplotlib openpyxl
That is the whole finance stack for the first six months. pandas for data, numpy for math, matplotlib for charts, openpyxl so it can read your Excel files.
If pip is not recognized, you missed the PATH box during install. Reinstall and tick it. This is the single most common place people give up, and it is a checkbox.
There is a second route worth knowing about: Python now runs inside Excel itself. If your organization is on Microsoft 365 that may be the softer landing, and Python in Excel covers it.
pandas, and the ten lines that do most of the work
Almost everything you will do in your first year is one of five operations. Read a file, filter it, group it, join it, write it out.
import pandas as pd
# read
df = pd.read_excel('trial_balance.xlsx', sheet_name='TB')
# filter
opex = df[df['Account'].str.startswith('6')]
# group
by_cc = opex.groupby(['CostCenter','Period'])['Amount'].sum().reset_index()
# join
mapping = pd.read_excel('cc_owners.xlsx')
by_cc = by_cc.merge(mapping, on='CostCenter', how='left')
# check before you trust it
print(by_cc['Amount'].sum(), opex['Amount'].sum())
# write
by_cc.to_excel('opex_by_cc.xlsx', index=False)
The print line is the one people leave out and it is the one that matters. Every transformation gets a tie-out. A merge that silently drops 400 rows because the cost center codes have trailing spaces will not raise an error, it will just give you a smaller number.
That failure mode is the whole reason a finance person should learn to read this rather than trust it. The code runs fine. The answer is wrong.
How I write Python now
I have not written a script from a blank file in over a year. The workflow is describe, review, run, fix.
The describe step is where it succeeds or fails. Vague in, garbage out, and the garbage looks professional.
I have an Excel file, trial_balance.xlsx, sheet TB.
Columns: Entity, Account, AccountDesc, Period, Amount, CostCenter.
Period is text like '2026-08'. Amount is a float, credits are negative.
Write Python using pandas that:
1. loads it
2. filters to accounts starting with 6
3. sums Amount by CostCenter and Period
4. joins a second file cc_owners.xlsx on CostCenter to add an Owner column
5. prints a tie-out comparing the summed total to the filtered total
6. writes the result to opex_by_cc.xlsx
Add a comment on any line where a finance person could get
a wrong answer without an error being raised.
That last instruction is worth adding to every prompt you write. It turns a code generator into something closer to a reviewer, and the comments it produces are usually where the real risk is.
Then read it before you run it. Three questions: what file does it read, what file does it write, and does it overwrite anything. That is the entire safety check and it takes fifteen seconds.
For the wider version of that workflow, AI coding for finance covers writing code with a model when you are not a developer.
The prompts, written out
The AI library for finance teams
The Python prompts above, the pandas tie-out pattern, and the review checklist I run before executing anything a model wrote. Free, and it lands in your inbox in about a minute.
Coming from VBA
If you have written VBA, you already have the hard part. You understand loops, variables, and the idea that a computer will do exactly what you said rather than what you meant.
Three differences worth knowing before you start.
- VBA lives inside a workbook. Python lives beside it. Your script reads the file, does the work and writes a new file, and the original is untouched, which is safer than it sounds when you are used to macros that edit in place.
- You almost never loop over rows in pandas. The VBA instinct is For Each cell in Range. In pandas you operate on the whole column at once, and code that loops row by row runs about a hundred times slower.
- No recorder. There is no Record Macro button, which is what most people used VBA for. A model is the replacement for that button, and it is a better one because you can ask it why.
Is VBA dead? No. If your job is automating Excel itself, ribbon buttons, userforms, things that live in the workbook and get emailed around, VBA still does that and Python does not. Office Scripts is the modern answer for the cloud version of the same job.
Where I would move off VBA is anything touching data outside Excel, anything on a schedule, and anything over a few hundred thousand rows.
Coming from R
R is the better language for statistics and it is not close. If your work is econometrics, survival analysis or anything where you want the model diagnostics printed properly, stay in R.
For finance work specifically, Python wins on the boring stuff. Reading ugly Excel files, talking to APIs, running on a schedule, being installed on a machine your IT department controls. And these days the model assistance is meaningfully better for Python because there is more of it in the training data.
| Task | Where I would do it |
|---|---|
| Cleaning and reshaping a monthly finance file | Python, pandas |
| Regression with diagnostics you plan to defend | R |
| A scheduled job that emails a report | Python |
| Exploratory charts while you think | R, ggplot2 is still nicer |
| Anything a colleague will have to maintain | Python, because more people read it |
The dplyr to pandas translation is close enough that a model will do it for you line by line. Paste your R and ask for the pandas equivalent with the same column names, and check the row count at both ends.
Four things I use it for
Concrete, from my own work, so you can judge whether any of it looks like your job.
- Splitting one 4.5 million row extract into per-entity files. Excel could not open the source. The script takes 40 seconds and runs on the first business day.
- Pulling FX rates from an API into a rate table each month, so the manual paste step stopped existing.
- Running the same forecast across 60 cost centers with different drivers, then writing 60 tabs into one workbook.
- Reading 200 PDF invoices for a one-off audit sample. That one was two hours of work and would have been three days.
What is not on the list: modeling, board decks, anything anyone else has to open. Those stay in Excel, because the output has to live somewhere a CFO can poke at it.
Where to start this week
Take one file you clean by hand every month. Write out what you do to it in plain English, step by step, the way you would explain it to a new starter.
Hand that to a model and ask for the pandas version with a tie-out at the end. Run it. Compare against the workbook you already built.
If the numbers match, you have your first script and you learned more in an hour than a tutorial gives you in a week. If they do not match, finding out why is the actual lesson, and it is a better one.
From there, AI tools for finance covers the wider tooling question, and AI in finance is what to reach for when the answer is not code at all.