We have to compute the average of of the 5th row in an excel sheet, saved as a csv file. The first row of the file has the names of the columns making them strings. I can't seem to get a code that loops around all the row[4] and compute it into one variable 'sum'. Here is my code. Also,
import csv
import os
sum = x_length = 0
with open('2.5_week.csv', newline='') as f:
rows = csv.reader(f)
for row in rows:
if row[4] is int:
sum = sum + float(row[4])
x_length = x_length + 1
x_average = sum/len(x_length)
print(x_average)
I'm using python 3.4.x