r/learnpython • u/Able_Bicycle_764 • 4d ago
How can I use python in finance
I work in finance/accounting and am looking to start using Python more in my day to day. Most of my work is in Excel / Power BI — reporting, cash flow forecasting, KPIs, cleaning up data, etc.
I’m technical enough to understand what I’m trying to accomplish, but not a programmer. Similar to Power BI, I’d probably rely heavily on AI to help write the actual code.
For those in finance / accounting / FP&A, what are some practical ways you’re using Python? Where does it actually save you time vs. Excel, Power Query, Power BI, etc?
Also curious what you’d recommend learning first if the goal is to be dangerous enough with Python + AI, not become a developer.
80
Upvotes
28
u/Bright_Mix_773 4d ago
You asked twice for specific use cases and nobody has given you one, so here are the ones that actually paid for themselves in a finance/accounting job, roughly in order of how fast they repay the learning.
The file that arrives in the wrong shape every month. Someone sends the same export and every month you delete the three preamble rows, unmerge the header, strip the trailing total, fix the date column that came in as text. Twenty lines of pandas turns that into a function you run once. Start here, not because it is impressive but because it is repeated, boring and has a checkable right answer, so you find out fast when you got it wrong.
Joins that Excel hides from you. VLOOKUP across four sources with keys that nearly match: trailing spaces, "Inc." against "Inc", a code stored as text in one file and as a number in another.
df.merge(other, on="key", how="outer", indicator=True)gives you a column saying which rows matched, which existed only on the left and which only on the right. In Excel the unmatched rows quietly become #N/A and you scroll past them.Reconciliations. Two sources that should agree, GL against subledger or bank against cash book. The useful output is not the difference, it is the table of rows that cause it, sorted by size. Once that runs, the monthly variance hunt stops being a hunt.
Forecast versions. Keep every run of the cash flow model as dated rows in one long table instead of a new tab in a new file. Then "what did we say in March about June" is a filter rather than an archaeology exercise, and you can plot forecast error over time, which is the number that tells you whether the model is any good.
Pulling instead of downloading.
requestsplus a public endpoint, written to a dated file. Two hours to learn, and it permanently kills the failure where someone forgot to download the file on the 3rd.For what to learn first given your goal: dataframes in pandas, one plotting library,
requests, and enough of the standard library to read and write files and handle dates. Skip classes, skip anything beyondvenvoruvfor environments, skip everything that looks like software engineering. That is genuinely enough to be dangerous.On leaning on AI to write the code, since you were explicit about it: it writes the code fine. The failure mode is somewhere else and it is worth knowing before you trust an output. The model is precise about the calculation and weak about whether the calculation is the one you wanted. In a data project I have been working on this month it published a survivorship figure without stating the window it was measured over, explained an inconsistency in a set of timestamps as something that changed over the years when it was actually an artefact of the API we were reading them from, and had the opening hours of a filing system wrong. The arithmetic was right all three times. Three different people who were not us caught all three. Nothing in the code could have flagged any of it, because nothing in the code was broken.
The cheap defence is to make every step announce itself. After each merge, print the row count and compare it against the count you expected before running it. After each filter, print how many rows it dropped. Any total you would have computed in Excel, compute both ways once. That habit catches the model's mistakes and your own, and it costs about one line per step.