Using Python to automate your Personal Finance Pt.2

Gabriel Shoaib
3 min readJul 21, 2021

--

Part 1. Proof of Concept CLICK HERE

Part 2. Storing Data Better (gspread)

Part 3. Plaid API

Part 4. NLP Classification

Part 5. Front End Design

In Part 1, we answered the most important question, “How much money am I spending per month?” We tackled this by aggregating all of our transaction reports from various debit and credit cards in order to see your monthly net growth or loss. After seeing a general trend of expenses, the next reasonable thing to ask is, “What am I spending my money on?”. That is what this section is going to cover.

Using gspread to store data

We’ll be storing our data in google sheets in order to more easily update and maintain the data over time. Gspread is a powerful package that lets us link google spreadsheet accounts to our python code. The instructions for setup are here:

Mapping bank reports

Once gspread is connected, the next step is to store our banking transactions into the spreadsheet. For each account, whether debit or credit, download the timeframe for transactions that you would like to assess. A 6 months window is a good starting place.

I wanted to see a more personal view of my data so I created a column “Category1”, in order to put in my own transaction labels. For the time being, this is a manual process but it will help out in the end.

Make sure that you store each of your bank accounts separately in different sheets and title them accordingly. Below, ensure that you change “Bank Account” to the name in your sheets.

I’m currently showing 4 different files, 2 debit and 2 credit. If yours are different, then you’ll need to modify the code to incorporate all your cards.

The Code

Everything is lined up, execute the code to aggregate and clean up your data. This will complete 95% of the work.

Monthly expense breakdown

Run the code below to see your monthly. Expenses. Change the date field to see your entries.

You can also see a full trend line of all your expenses to see the overall view of the data.

Where do we go from here?

After completing this portion of the project, there are new goals and questions that need to be addressed.

  1. Update the bank expenses automatically without manual intervention? Plaid might be a tool that answers this question.
  2. Incorporate both graphs into a single dashboard view. Plotly and Dash will be a good starting point.
  3. Automatically identify the category for each of the charges.
  4. Now that we know what we’re spending our money on each month, I want to know what my net earning or loss is per month. Regardless of what I’m spending on, this indicator will give me a better view of my earning and spending per month.

Access the full code here!

Sign up to discover human stories that deepen your understanding of the world.

--

--

Gabriel Shoaib
Gabriel Shoaib

Written by Gabriel Shoaib

Data guy but with an interest in Technology, Marketing, Startups and some outdoor stuff.

Responses (1)

Write a response