I have a set of data describing each people's spending in an excel file with their names as first 2 columns and spending on each day within a week as the next few columns. Such as:
name, mon, tues, wed, thurs, fri
bob,120,130,124,125,177
ann,119,128,245,90,77
sam,200,78,220,234,168
Now I want to find out :
- the average spending of them each day
- the person who spends the max each day
I've gotten this code so far:
import csv
with open('spending.csv', newline = '') as f:
reader = csv.reader(f)
next(reader)
r1 = [float(row[3]) for row in reader]
avg1 = round(sum(r1) / len(r1),2)
r2 = [float(row[4]) for row in reader]
avg2 = round(sum(r2) / len(r2),2)
r3 = [float(row[5]) for row in reader]
avg3 = round(sum(r3) / len(r3),2)
r4 = [float(row[6]) for row in reader]
avg4 = round(sum(r4) / len(r4),2)
r5 = [float(row[7]) for row in reader]
avg5 = round(sum(r5) / len(r5),2)
print("================================================")
print("{0:^10}|{1:^10}|{2:^10}|{3:^10}|{4:^10}".format(avg1,avg2,avg3,avg4,avg5))
However, I got error like this:
avg2 = round(sum(r2) / len(r2),2)
ZeroDivisionError: division by zero
Please help me with this, and how can I find out the person spends the most each day? Is there a function max()? Appreciate your help!