-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2.py
More file actions
48 lines (34 loc) · 1.34 KB
/
Copy pathmain2.py
File metadata and controls
48 lines (34 loc) · 1.34 KB
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
import os
import csv
csvpath = os.path.join("Resources/budget_data.csv")
print("=================================================")
print("Financial Analysis")
print("=================================================")
#Find the total # of months in entire data.
#Read the csv file.
with open(csvpath, 'r') as csvfile:
csvreader = csv.reader(csvfile)
#Total number of months included in the date.
csvfile.seek(0)
next(csvreader)
row_count = sum(1 for row in csvreader)
print(f"Total Months: {row_count}")
#Find Total Net amount of profit/losses in entire data.
sum_profit = 0
sum_loss = 0
total_profit_loss = 0
profit = 0
for row in csvreader:
profit = int(row[1])
if profit >= 0:
sum_profit = sum_profit + profit
elif profit <= 0:
sum_loss = sum_loss + profit
total_profit_loss = sum_profit + sum_loss
print(f'Total Net amount of profit/losses is {total_profit_loss}')
#Find average(mean) of changes in profit/losses in entire data.
average = total_profit_loss / int(row[0])
print(f'Average of changes in profit/losses is {average}')
#Find greatest increase in profits (include both dates & amounts).
#Find greatest decrease in losses (include both dates & amounts).
#Print the analysis to terminal, and export .txt file with results.