Day 40 of 100 Days Coding Challenge: Python
Iāve been tracking my personal expenses in Excel for yearsāpart frugality, part paranoia, and part curiosity about where my coffee budget keeps disappearing. While rows and columns get the job done, they arenāt exactly thrilling.
So, I decided to give my budget a little makeover. I created a Python Expense Tracker App. Over the past couple of days, Iāve been fiddling with matplotlib, playing with lines and bars like a spreadsheet Picasso. Today, I thought, āWhy not turn this into a pie chart?āābecause nothing says responsible adulting like slicing your expenses into pizza-shaped regret. For this mini project, I spared myself the embarrassment of my actual spending and used a clean, innocent example instead. Baby steps.
Todayās Motivation / Challenge
We all love to believe weāre financially savvy⦠until we see it in a chart and realize weāve spent more on takeout than utilities. Visualizing data is like turning on a light in a messy roomāyou suddenly see everything you were ignoring. Pie charts are a beginner-friendly way to practice working with visualizations, and letās face it: theyāre much easier to interpret than bar charts if youāre half-awake with your morning tea.
Purpose of the Code (Object)
This code creates a pie chart that shows how your expenses are split among categories like rent, groceries, and āmiscellaneous,ā which is often just code for impulse purchases. It helps turn numbers into visuals so you can actually understand where your money goesāwithout scrolling through endless rows in a spreadsheet.
AI Prompt:
Write a Python script that generates a pie chart of personal expenses using matplotlib.
Functions & Features
- Breaks down expenses into categories.
- Assigns colors to each slice for easier viewing.
- Automatically calculates percentages and displays them on the chart.
Requirements / Setup
You’ll need:
pip install matplotlib
Minimal Code Sample
plt.pie(expenses, labels=categories, autopct=’%1.1f%%’)
plt.axis(‘equal’) # Makes the pie chart look like a circle
This generates the core of your pie chart and ensures it’s not shaped like an egg.
Notes / Lessons Learned
The code itself wasnāt hard to wrangleāitās the file names that got me. I confidently ran my script, only to watch Python stare at me blankly. Turns out Iād named the file incorrectly and had the right environment with the wrong target. Itās like dialing the right number but calling the wrong person. Also, adding more categories is easy, but unless you want all your slices to look the same shade of gray, youāll need to manage your colors better. Next time, pulling data from a CSV file, like a bank statement, would make the tool far more practicalāand possibly more shocking.
Optional Ideas for Expansion
- Import expense data directly from a CSV file.
- Add a legend to clarify which color means what (before purple becomes both rent and groceries).
- Turn it into a simple GUI with category input for non-coders.
