Program for Tracking and Visualizing Monthly Expenses

Ashish Nair
Analytics Vidhya
Published in
3 min readOct 12, 2020
Photo by rupixen.com on Unsplash

Those who don’t manage their money will always work for those who do.” — Dave Ramsey

We all have tried to maintain a journal to list down our monthly Incomes and Expenses but only a few of us succeed in doing so regularly. I for one find it really tedious to jot down all the Income-Expense details regularly and I fail to maintain the accounts properly.

So, I came up with this simple but useful Python program that you can use to fill in your income-expense details on the go, and you can even visualize graphically how much you are spending as opposed to your earnings.

Lets start coding …

We will be using two modules ;

Pandas to store and read the monthly statements in csv form and Matplotlib to visualize the data in the form of plots.

Now lets install the modules,

pip install pandas
pip install matplotlib

So, now that you’ve installed the required modules lets import them,

We will be using functions to perform the various parts of our programs, so lets write some functions.

First function that we will be defining is values() we will use it to collect the income-expense values.

This function takes in the input for income and expense details, like values and description of the same, and passes these details in to the tracker() function as arguments.

The tracker() function uses the data fed into it to create a .csv file with the name of the month of which the income-expense data relate to. It uses the month_tracker() function to return the name of the current month and passes the month name to the checkIf() , to check if the csv file with name of the month is empty and if it is empty the .csv file would be written in ‘w’ mode else it will be appended in ‘a’ mode.

Lets define the month_tracker() & checkIf() functions,

As you might have noticed, after creating the .csv file for the particular month we call another function, Balance_get() , this function returns the balance for the current month (i.e Income-Expenses).

We also define another function to view the balances for all the months, of which we have entered data.

Now to the fun part of actually visualizing our data, we define a chart() function. The chart function will plot a bar plot for the months of which we have entered data and have created .csv files for.

The chart() plots a graph as such,

Function output

We have used the ‘fivethirtyeight’ style, but there are a lot of style options available in matplotlib. You can use print(styles.available) to view a list of all the available options.

Now, coming to actually calling all the above functions.

I have used the function calls to make it feel like an application so that it is fun and easy to use.

Project Ideas

You could use this program and try to make a GUI based application using PyQt or Tkinker.

Conclusion

That’s it go try running this code yourself, you can get the whole code from my GitHub Repository here.

--

--