
“You can’t change what you can’t measure. Python helped me do both.”
Table of Contents
- Introduction: The Financial Fog
- Why I Wanted to Analyze My Spending
- Why I Chose Python Over Excel
- Tools and Libraries I Used
- Step 1: Gathering My Raw Financial Data
- Step 2: Cleaning and Structuring the Data with pandas
- Step 3: Categorizing Transactions
- Step 4: Creating Monthly Reports and Spending Summaries
- Step 5: Visualizing Patterns with matplotlib & seaborn
- Step 6: Discovering Hidden Habits and Emotional Spending
- Step 7: Automating the Workflow with Python
- Step 8: Expanding into Budget Forecasting and Savings Tracking
- Unexpected Insights I Found
- What Changed in My Behavior
- How You Can Do the Same (Beginner-Friendly Walkthrough)
- Going Further: Net Worth, Investments, and Passive Income
- My Biggest Lessons Learned
- Final Thoughts: Code Meets Clarity
- FAQ
1. Introduction: The Financial Fog
Before I tracked my spending, everything felt like a black box.
Some months I saved money. Some I didn’t. But I couldn’t explain why.
So I turned to Python — not just as a programming language, but as a lens for financial clarity.
2. Why I Wanted to Analyze My Spending
- I didn’t trust budgeting apps
- Excel was chaotic
- My bank statements were dense and inconsistent
- I had no idea how much I was spending on food delivery (spoiler: too much)
3. Why I Chose Python Over Excel
Feature | Excel | Python |
---|---|---|
Flexibility | Limited | Total control |
Repeatability | Manual | Fully automated |
Scalability | Struggles with large data | Handles 10,000+ rows easily |
Visualization | Decent | Customizable (matplotlib, seaborn) |
Also: I just wanted to learn something useful and personal with Python.
4. Tools and Libraries I Used
pandas
– for data wranglingmatplotlib
– basic graphsseaborn
– nicer visualizationsdatetime
– parsing and groupingjupyter notebook
– exploration and outputre
(regex) – text-based transaction parsing
5. Step 1: Gathering My Raw Financial Data
- Exported CSVs from 3 sources:
- Bank account
- Credit card
- PayPal
Each had different structures, formats, encodings, and even date styles (MM/DD/YYYY
vs YYYY-MM-DD
).
Python to the rescue:
import pandas as pd
df1 = pd.read_csv('bank.csv')
df2 = pd.read_csv('creditcard.csv')
df3 = pd.read_csv('paypal.csv')
data = pd.concat([df1, df2, df3], ignore_index=True)
6. Step 2: Cleaning and Structuring the Data with pandas
Common issues:
- Missing values
- Duplicates
- Strange encodings (
à
,™
, etc.) - Inconsistent column names
Sample code:
data = data.dropna(subset=['Amount'])
data['Date'] = pd.to_datetime(data['Date'])
data['Amount'] = data['Amount'].astype(float)
7. Step 3: Categorizing Transactions
No app knows your habits better than you.
My Approach:
- Manually built a dictionary of keywords → categories
rules = {
'Grocery': ['walmart', 'whole foods'],
'Dining': ['uber eats', 'mcdonalds'],
'Rent': ['property management', 'rent'],
}
- Applied it using regex and
.apply()
Sample:
import re
def categorize(desc):
desc = desc.lower()
for cat, keywords in rules.items():
if any(k in desc for k in keywords):
return cat
return 'Other'
data['Category'] = data['Description'].apply(categorize)
8. Step 4: Creating Monthly Reports and Spending Summaries
Grouped and summarized using groupby
:
monthly = data.groupby([data['Date'].dt.to_period('M'), 'Category'])['Amount'].sum().unstack().fillna(0)
Then exported to CSV, sent to my phone weekly.
9. Step 5: Visualizing Patterns with matplotlib & seaborn
Sample graph:
import seaborn as sns
import matplotlib.pyplot as plt
monthly.T.plot(kind='bar', stacked=True, figsize=(12, 6))
plt.title("Monthly Spending by Category")
Visuals helped me:
- Spot spikes in certain months
- Compare categories side by side
- Track declining (or growing) expenses
10. Step 6: Discovering Hidden Habits and Emotional Spending
What I found:
- I spent more on food delivery after long workdays
- Shopping spiked on Sundays
- Some recurring payments (subscriptions!) I had forgotten about
This wasn’t just data.
It was a mirror.
11. Step 7: Automating the Workflow with Python
Wrote a script to:
- Ingest all CSVs in
/downloads
- Clean and merge
- Categorize
- Generate reports and visualizations
- Email results to myself weekly
Scheduled using cron
(Mac) and Task Scheduler
(Windows)
2. Step 8: Expanding into Budget Forecasting and Savings Tracking
Used historical spending to:
- Set monthly budgets
- Forecast next month based on moving average
- Compare actuals vs budgeted amounts
Plotted savings rate over time:
data['YearMonth'] = data['Date'].dt.to_period('M')
monthly_total = data.groupby('YearMonth')['Amount'].sum()
13. Unexpected Insights I Found
- Spending spiked during social events (not dates!)
- I underestimated transportation by 40%
- The $5–$15 range accounted for most unnecessary expenses
- I had 3 duplicate insurance charges for months
14. What Changed in My Behavior
After a month of looking at these visuals weekly:
- I stopped ordering food during workdays
- Unsubscribed from unused platforms
- Combined two insurance plans
- Set spending triggers (alerts) in code
15. How You Can Do the Same (Beginner-Friendly Walkthrough)
Even if you don’t code:
- Export your bank transactions
- Learn
pandas
basics (Jupyter + 3 tutorials) - Build a simple categorizer
- Use
matplotlib
to chart your data - Repeat monthly
You’ll be amazed.
16. Going Further: Net Worth, Investments, and Passive Income
I now track:
- Investment performance (ETF data via API)
- Net worth across accounts
- Passive income (dividends, blog, etc.)
Even built a simple net worth dashboard with streamlit
.
17. My Biggest Lessons Learned
- Awareness is the first step to control
- Most of my bad habits were emotional, not financial
- Automation beats willpower
- Code is leverage — and it compounds
18. Final Thoughts: Code Meets Clarity
You don’t need to be a developer.
You just need to be curious and consistent.
Python gave me financial self-awareness.
Not with charts.
But with habits, patterns, and better decisions.
19. FAQ
❓ I’m not a coder. Can I still do this?
Yes. Start with pandas
crash courses and YouTube tutorials.
❓ Is this better than budgeting apps?
It’s more personal, flexible, and insightful — but requires setup.
❓ What if I use multiple currencies/accounts?
Use exchange rates and normalize in a separate column.
❓ Can I track subscriptions too?
Yes. Use keyword tagging or regex rules.
📌 Final Thought: Your bank knows how you spend.
Python lets you know — and gives you the power to change it.