Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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))


id 85 86 87 88 89 91 low 0 0 0 0 0 0 age 19 33 20 21 18 21 Iwt 182 155 105 108 107 124 race 2 3 1 3 smoke 0 0 

id 85 86 87 88 89 91 low 0 0 0 0 0 0 age 19 33 20 21 18 21 Iwt 182 155 105 108 107 124 race 2 3 1 3 smoke 0 0 1 1 1 O ptl 0 0 0 0 0 ht 0 0 0 0 0 ui 1 0 0 1 1 0 ftv 0 3 2 0 0 bwt 2523 2551 2557 2594 2600 2622

Step by Step Solution

3.49 Rating (152 Votes )

There are 3 Steps involved in it

Step: 1

To make your function more generic and accept a column number as a parameter to calculate the mean ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Accounting and Reporting a Global Perspective

Authors: Michel Lebas, Herve Stolowy, Yuan Ding

4th edition

978-1408066621, 1408066629, 1408076861, 978-1408076866

More Books

Students also viewed these Programming questions