Python error with getting the mean of values in a list

Hello there I have been trying to implement the equation of xy_mean into my code down below however I am just unable to do it. The code below gets the elements from a very large list and uses them for equations for (x_mean, y_mean, x_squared_mean, xy_mean)


n is a constant number that all the equations are calculated with

x_mean: (1+2+3)/ n *note that for the second set of numbers it will go like (2+3+4)/n

y_mean : sum/ n = (418.98 + 416.49 + 452)/n

xy_mean = (418.981 + 416.492 + 452*3)/n

x²_mean = (1²+2²+3²)/ n

**number is equal to n from explained in the formulas above 
price_Closes = [*long list of numbers]
PC_list = list(map(float, price_Closes))
for i in range(len(PC_list)-(number-1)):
    #Getting the y mean
    y_mean = sum(PC_list[i:i+number])/number
    x_mean = reg_counter/2*(1 + reg_counter)
    x_squared_mean = reg_counter*(reg_counter+1)*(2*reg_counter+1)/6
    xy_mean = sum(PC_list[i:i+number])/number
    y_std = 0
    reg_counter += 1

    for j in range(number):

        y_std += (PC_list[i+j]-y_mean)**2

    y_std = round((y_std/(number-1))**(0.5), 1)


Read more here:

Content Attribution

This content was originally published by liliamhere at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: