initial
This commit is contained in:
48
analyze.py
Normal file
48
analyze.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import csv
|
||||
|
||||
reader = csv.DictReader(open('amex2.csv', newline=''))
|
||||
|
||||
data = []
|
||||
total_amounts = {}
|
||||
for row in reader:
|
||||
data.append(row)
|
||||
|
||||
def sameMerchant(data, sorted=True):
|
||||
amounts_by_description = {}
|
||||
for item in data:
|
||||
description = item['Description']
|
||||
amount = float(item['Amount'])
|
||||
if description in amounts_by_description:
|
||||
amounts_by_description[description] += amount
|
||||
else:
|
||||
amounts_by_description[description] = amount
|
||||
|
||||
if sorted:
|
||||
for description, total_amount in amounts_by_description.items():
|
||||
print(f"{description}: {total_amount}")
|
||||
else:
|
||||
for description, total_amount in sorted(amounts_by_description.items(), key=lambda x: x[1], reverse=True):
|
||||
print(f"{description}: {total_amount}")
|
||||
|
||||
def sameCategory(data, sorted=True):
|
||||
amounts_by_category = {}
|
||||
for item in data:
|
||||
category = item['Category']
|
||||
amount = float(item['Amount'])
|
||||
if category in amounts_by_category:
|
||||
amounts_by_category[category] += amount
|
||||
else:
|
||||
amounts_by_category[category] = amount
|
||||
|
||||
if sorted:
|
||||
for category, total_amount in amounts_by_category.items():
|
||||
print(f"{category}: ${total_amount}")
|
||||
else:
|
||||
for category, total_amount in sorted(amounts_by_category.items(), key=lambda x: x[1], reverse=True):
|
||||
print(f"{category}: ${total_amount}")
|
||||
|
||||
sameCategory(data)
|
||||
|
||||
# for item in data:
|
||||
# if "Merchandise & Supplies-Music & Vidkoijoeo" in item["Category"]:
|
||||
# print(item['Description'])
|
||||
Reference in New Issue
Block a user