'Mean and Standard Deviation of Columns Using Default Functions

The problem is asking to make a function to find the mean and standard deviation of the given excel file. The twist is that the last column of each row represents whether if the row is a '0' row or a '1' row. We need to find a function that you can input on many columns you want to test and if you want to test the '0's and/or the '1's. Here's my current code:

def mean(column, one, zero):
    for item in data:
        if item in data:
            item[[8]] = 0
        elif item in data:
            item[[8]] = 1
        sum = sum(item[[column]])
    return sum / len(item[[column]])
print(mean(1))

def standard_deviation(column, one, zero):
    for item in data:
        if item in data:
            item[[8]] = 0
        elif item in data:
            item[[8]] = 1
    mean = mean(column)
    temp = 0
    for item in data:
        temp = temp + ((item - mean) ** 2)
    return (temp / len(column)) ** 0.5

And the data that was given to us:

[['1', '85', '66', '29', '0', '26.6', '0.351', '31', '0'], ['8', '183', '64', '0', '0', '23.3', '0.672', '32', '1'], ['1', '89', '66', '23', '94', '28.1', '0.167', '21', '0'], ['0', '137', '40', '35', '168', '43.1', '2.288', '33', '1'], ['5', '116', '74', '0', '0', '25.6', '0.201', '30', '0'], ['3', '78', '50', '32', '88', '31.0', '0.248', '26', '1'], ['10', '115', '0', '0', '0', '35.3', '0.134', '29', '0'], ...

and so forth



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source