To calculate mean when frequency table is given

#python #statistical_tools

when two lists have been given;one is for values of that variable and second is for its frequencies.

In these cases we have to multiply two lists.so,consider a new list as “temp” and then proceed with the below syntax.

we can simply print mean or can also insert mean of that list in a dictionary as a key.

import math
X=[1,2,3,4,5]
fx=[2,4,6,8,10]
temp=[]
i=X[0]*fx[0]
a=0
for i in range(0,len(X)):
    temp=temp + [X[i]*fx[i]] 
    a=a+temp[i]
    
print(temp)
print("sum of multiples",a)
b=0
for i in range (0,len(X)):
    b=b + fx[i]
print("sum of frequ.",b)
def mean(X):
     result=a/b
     return result
print("mean=",mean(X))
d={"mean=":mean(X)}
for key in d:
    print(key,d[key])


output:-

Leave a Reply