Skip to content

Instantly share code, notes, and snippets.

@KickedDroid
Created March 23, 2021 23:21
Show Gist options
  • Save KickedDroid/23075f68c10fd5c548cb22c845ad0f63 to your computer and use it in GitHub Desktop.
Save KickedDroid/23075f68c10fd5c548cb22c845ad0f63 to your computer and use it in GitHub Desktop.
import numpy as np
from pathlib import Path
import csv
csvPath = Path("budget_data.csv")
# Get the total amount of profit/loss
total = 0
average = 0
minimum = 0
maximum = 0
totalMonths = 0
minDate = ''
maxDate = ''
with open(csvPath, 'r') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',')
header = next(csvreader)
for row in csvreader:
total += int(row[1])
totalMonths +=1
if minimum == 0:
minimum = int(row[1])
minDate = str(row[0])
elif int(row[1]) < minimum:
minimum = int(row[1])
minDate = str(row[0])
elif maximum == 0:
maximum = int(row[1])
maxDate = str(row[0])
elif int(row[1]) > maximum:
maximum = int(row[1])
maxDate = str(row[0])
average = total / totalMonths
print("Total Months: " + str(totalMonths) )
print('Total: $'+ str(total))
print('Average Change: $'+ str(average))
print('Greatest Increase in Profits: '+ maxDate +' '+ str(maximum))
print('Greatest Decrease in Profits: '+ minDate +' '+ str(minimum))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment