If you’ve ever tried to complete a data science project that revolves around personal finances, you’re probably familiar with the joys of bank-exported CSV files for transaction data.
Put short — they’re absolutely awful. Most banks will allow you to export your bank statement as a CSV, but what a lot of them don’t tell you is how terribly structured these CSV files are. Different banks use different header names for the amount, reference and so on, and hard coding every single bank is nigh on impossible.
This is where QIF files come in. QIF, or Quicken Interchange Format, is a file format developed by Intuit initially for use in their QuickBooks product. However, the format is very old now (older than OFX, even).
Regardless of this, most banks and other financial institutions (stock brokers, etc.) will offer QIF as an option when exporting your data. Despite its age, the QIF file format is useful because:
- It’s standardised — no more hard coding different CSV schema for different banks
- It’s widely used
- It’s written in plain text, so it’s really easy to parse
Quiffen is a Python package for parsing QIF files and exporting the data in more useful formats, such as dictionaries or pandas DataFrames. Quiffen can be installed from the command line by running:
pip install quiffen
From there, you’re ready to start analysing your data!
Parsing QIF Files
Below is a code sample of how to parse a QIF file and export the transactions within into a DataFrame:
You can choose different data to export, such as the categories (which are represented by trees) or the accounts stored in the
Qif object. You can also export the data from to a CSV with headers which will be consistent every time with the
Creating Your Own QIF Files
Quiffen also supports QIF structure creation and export! You can create your own
Qif objects and add accounts, transactions, categories, classes and more to it. An example of this is shown below, but a full API reference can be found on the Quiffen docs:
You can view the full source code for the Quiffen package on GitHub. Any feedback or (constructive!) criticism is greatly appreciated!
I would highly recommend trying out Quiffen with your own transaction data, and if you also want to check out the program that got my financial ass into gear, please do that also!
Also, if you have any questions, please feel free to send them to me on GitHub or connect with me on LinkedIn! I love writing about my projects so you might like to follow me on Medium too. Alternatively, subscribe to my newsletter!
That’s all for this one! I hope you enjoyed it, and any feedback is greatly appreciated!