Skip to content

Instantly share code, notes, and snippets.

@soerface
Created October 29, 2016 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soerface/3f4fcf5572e376f7eb93cf5c84a85bae to your computer and use it in GitHub Desktop.
Save soerface/3f4fcf5572e376f7eb93cf5c84a85bae to your computer and use it in GitHub Desktop.
import argparse
import csv
from datetime import datetime
from matplotlib import pyplot
import numpy as np
parser = argparse.ArgumentParser(description='Plot N26 CSV')
parser.add_argument('filepath', type=str, help='path to csv file downloaded from N26')
args = parser.parse_args()
balances = []
dates = []
transactions = []
categories = set()
with open(args.filepath, 'r') as f:
reader = csv.reader(f, delimiter=',', quotechar='"')
# skip header
next(reader)
current_balance = 0
for i, row in enumerate(reader):
date, payee, account_number, transaction_type, payment_reference, category, amount_eur, amount_foreign, type_foreign, exchange_rate = row
date = datetime.strptime(date, '%Y-%m-%d').date()
amount_eur = float(amount_eur)
current_balance += amount_eur
categories.add(category)
balances.append(current_balance)
transactions.append(amount_eur)
dates.append(date)
print(categories)
pyplot.bar(dates, [max(0, t) for t in transactions], color='g', linewidth=0)
pyplot.bar(dates, [min(0, t) for t in transactions], color='r', linewidth=0)
pyplot.plot(dates, balances, marker='x', linestyle='-')
pyplot.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment