Personal expense tracker with charts
Log daily spending by category, see monthly totals and draw a pie chart of where the money went.
What you'll learn
- โThe csv module and dates
- โGrouping and summing data
- โDrawing charts with matplotlib
What you'll build
- โAdd an expense (amount, category, note, date)
- โMonthly summary by category
- โBudget limit warnings
- โPie and bar charts saved as PNG
Step-by-step guide
- 1
Pick the file format
Use expenses.csv with columns date,amount,category,note. Create it with a header row if missing.
- 2
Add expenses
Ask for amount (validate it is a positive number), category from a fixed list, optional note; default date is today.
- 3
Read and filter by month
Read rows with csv.DictReader, parse date with datetime.strptime and keep the rows for the chosen month.
- 4
Summarise by category
Use a dict or collections.defaultdict(float) to total each category; print a sorted table with percentages.
- 5
Warn on budgets
Store monthly limits per category in budget.json and print a warning when a category crosses 80% and 100%.
- 6
Draw charts
pip install matplotlib; plt.pie(totals.values(), labels=totals.keys(), autopct="%1.0f%%") and save with plt.savefig("march.png").
- 7
Add a menu
Wrap everything in a loop menu: 1 Add, 2 Summary, 3 Chart, 4 Budgets, 5 Exit.
๐ Make it stand out
- +Rewrite the analysis with pandas
- +Import a bank statement CSV
- +Turn it into a Streamlit web app