-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement_visualizer.py
62 lines (45 loc) · 1.61 KB
/
statement_visualizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import csv
import matplotlib.pyplot as plt
i = 0
date, expenses = [], []
labelExpense = [{"Label": "", "Amount": 0}]
input_path = r'\statement.CSV'
output_path = r'\statement.CSV'
def main():
with open(input_path) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row.get('Type') == 'CHASE_TO_PARTNERFI' or \
row.get('Type') == 'QUICKPAY_DEBIT' or \
row.get('Type') == 'ACH_DEBIT':
continue
amt = float(row.get('Amount'))
if amt is not None and amt < 0:
amt *= -1.00
label = row.get('Description')[:5]
# day = row.get('Posting Date')
# Expenses over time (per day)
# if len(date) > 0 and day == date[-1]:
# expenses[-1] += amt
# else:
# expenses.append(amt)
# date.append(day)
if len(labelExpense) > 0 and label == labelExpense[-1]["Label"]:
labelExpense[-1]["Amount"] += amt
else:
labelExpense.append({"Label": label, "Amount": amt})
labelExpense.sort(key=lambda l:l["Label"])
# with open(output_path, 'w+') as csvout:
# writer = csv.writer(csvout)
# writer.writerows(labelExpense)
labelList = []
expenseList = []
for i in labelExpense:
labelList.append(i["Label"])
expenseList.append(i["Amount"])
plt.plot(labelList, expenseList)
plt.ylabel('Expense')
plt.xlabel('Label')
plt.show()
exit()
main()