Make the function more generic rather than hard coding the age column, have the function accept a
Fantastic news! We've Found the answer you've been seeking!
Question:
Make the function more generic rather than hard coding the age column, have the function accept a second parameter the column number that the function should take the average of. for example, if you want to calculate the mean of column #3 of a table called "mydata.csv". the parameters should will be mean_calc('mydata.csv', 3).
import csv
line = 0
tot = 0.000
with open ('birthwt(4).csv', 'r') as csv_file:
birthwt = csv.reader (csv_file, delimiter = ',')
for row in birthwt:
if line !=0:
print(row[2])
tot = tot + float(row[2])
line +=1
print(tot)
print(str(tot/line-1))
Related Book For
Financial Accounting and Reporting a Global Perspective
ISBN: 978-1408076866
4th edition
Authors: Michel Lebas, Herve Stolowy, Yuan Ding
Posted Date: