Tracking personal finances can be tedious. It either requires a massive time investment to keep everything well categorized as new transactions come in or it is far from accurate with tools that try to do prediction to define categories for you. Perhaps it works fine for names such as “Wall Mart” or “Starbucks” but your local bakery called “Morty’s Place” is definitely not going to get picked up by the model. Many personal finance tools allow you to manually adjust these categories but that is just as tedious as doing it from scratch.
With PersonalFinance I want to make it easier to manage your finances. Through defining each category with appropriate keywords, you can be sure that the model will categorise transactions how you defined them. This is because it is not a generic model that is trained on a large dataset of transactions from all over the world. It is trained on your own data, which means that it will be able to categorise transactions that are specific to you. This results in Morty’s Place being correctly categorised as a Bakery.
To assist in not needing to get exact matches, the package makes use of the Levenshtein distance to determine how similar two strings are. This means that if you have a category called “Groceries” with the keyword “Supermarket” and a transaction comes in with the name “Rick’s Super Market”, it will still be categorised as “Groceries”. There is a limited amount of Mumbo Jumbo going on here on purpose so that it still becomes logical why it is categorised as such.
By doing most of these things through Python and Excel, you have the complete freedom to decide what to do with the output. For example, you can use it to create your own personalized dashboards via any programming language or application such as Excel, PowerBI, Tableau, etc. I don’t want to bore you with custom dashboards that I tailored to myself just so that you can come to the conclusion that it isn’t a perfect fit for you.
Before installation, consider starring the project on GitHub which helps others find the project as well. Click the image to visit the repository and Star the project.
To install the PersonalFinance it simply requires the following:
pip install personalfinance -U
Then to use the features within Python use:
from personalfinance import Cashflow cashflow = Cashflow()
This will generate the configuration file for you to use which you can supply again by using
configuration_file='cashflow.yaml'. See below for more information about each capability and what you can do with this file.
How-To Guides for PersonalFinance
This section contains a list of How-To guides for Personal Finance These guides are meant to show you how to use Personal Finance to gain insights into your own personal financnes. The guides are written in the form of Jupyter Notebooks. You can view the notebooks by clicking on the button below the description.
Getting Started with Personal Finance
This notebook demonstrates an example how to use Personal Finance to understand what the application offers and how you can leverage it for your own personal finance. It helps in understanding how the package is created and how you can use it both in Python and Excel.
Managing your Personal Finances
This notebook explains in detail how to use your own transaction files to manage your personal finances. It explains in detail how to use the configuration file and how you can leverage the created datasets to gain insights in your prsonal finances.
To get started, you need to acquire a configuration file that defines your transactions. This file consists of things such as the location of the datasets, the columns that define e.g. the name, the amount, the date and the categories and keywords that can be used to categorize transactions. The configuration file is automatically downloaded on initialization.
To see an example, you can run the following code:
from personalfinance import Cashflow cashflows = Cashflow(example=True) cashflows.perform_analysis()
Before it does anything, it will download the example datasets as found here. This is merely meant for you to understand how the functionality works. When you are ready to use it for your own cashflows, you can simply remove the
example=True argument and supply your own configuration file. If you don’t have one yet, it will automatically supply one if you use
Cashflow(). See the Notebooks as found here for an in-depth explanation.
perform_analysis functionality does the following things:
- It reads all the cashflow datasets based on the configuration file’s
file_locationparameter. This can be a single file, a selection of files or an entire folder. It also applies the cost or income indicator if the numbers in your file are all positive (e.g. a column that says “Plus” or “Minus”) if chosen.
- It starts applying categorization based on the
categoriessection in the configuration file. It uses Levenshtein distance to find matches that are closely related (e.g. ‘Tim’s Bakery’ and ‘Bakery’ would fit in the same category)
- It generates multiple transactional and categorized overviews on a weekly, monthly, quarterly and yearly basis.
- It generates an Excel file in which all of the results are displayed in a neat format based on the
excelsection of the configuration file. This is optional and can be disabled by setting
See the resulting image for the file that is generated based on the example dataset:
Besides that, you don’t have to continue in Excel if you are handy with Python as all created datasets can be directly accessed in Python as well. All of the datasets can be accessed through the related
get functions for example:
|Yearly||Totals||Income||Investing||Charity||Government||Health and Insurance||Housing||Study||Subscriptions||Transactions||Transport||Sports||Shopping||Groceries||Food and Drinks||Holidays||Cultural||Festivals, Clubs and Concerts||Other|
And the following:
|2023-09-04/2023-09-10||2023-09-10||thuisbezorgd - Omitted due to Privacy Reasons||-12.55||thuisbezorgd - Omitted due to Privacy Reasons||Food and Drinks||thuisbezorgd||100%|
|2023-09-04/2023-09-10||2023-09-10||Tinq - Omitted due to Privacy Reasons||-53.81||Tinq - Omitted due to Privacy Reasons||Transport||Tinq||100%|
|2023-09-11/2023-09-17||2023-09-12||geldmaat - Omitted due to Privacy Reasons||-18.43||geldmaat - Omitted due to Privacy Reasons||Transactions||geldmaat||100%|
|2023-09-11/2023-09-17||2023-09-13||asr - Omitted due to Privacy Reasons||12.2||asr - Omitted due to Privacy Reasons||Income||asr||100%|
These datasets make it possible to plot the spending pattern over time for each category. This can be simply by selecting the column and using
.plot() from Pandas but it also possible to create a larger overview as shown below:
import matplotlib.pyplot as plt # Obtain the Quarterly Cashflow Overview quarterly_cashflows = cashflows.get_period_overview(period='quarterly') # Define the colormap cmap = plt.get_cmap('tab20c') # Create the figure and axes fig, axes = plt.subplots( nrows=2, height_ratios=[6, 1], figsize=(30, 10)) # Plot the data per category quarterly_cashflows.plot.bar( stacked=True, colormap=cmap, title="Quarterly Cashflow Overview", ax=axes) # Calculate the totals totals = quarterly_cashflows.sum(axis=1) # Plot the totals totals.plot.bar( color=['g' if x >= 0 else 'r' for x in totals], ax=axes) # Format the plot by rotating labels and adjusting space plt.xticks(rotation=45) fig.subplots_adjust(wspace=0, hspace=0)
This returns the following plot: