You are on page 1of 1

3/5/24, 10:02 PM Untitled2 - Jupyter Notebook

In [ ]: # Mean of Group Data


import pandas as pd
df=pd.read_excel("file_1.xlsx")
df[["Lower","Upper"]]=df["class_Interval"].str.split("-",expand=True)
df["Midpoint"]=(df["Lower"].astype("float")+df["Upper"].astype("float"))/2
df["fy"]=df["Frequency"]*df["Midpoint"]
sum_fy=df["fy"].sum()
sum_f=df["Frequency"].sum()
Mean=(sum_fy/sum_f)
print("The value of Mean is =", Mean)

In [ ]: # Median of Group Data


import pandas as pd
df=pd.read_excel("file_2.xlsx")
df[["Lower","Upper"]]=df["Class_interval"].str.split("-",expand=True)
df["LCB"]=df["Lower"].astype("float")-0.5
df["UCB"]=df["Upper"].astype("float")+0.5
df["cum_sum"]=df["Frequency"].cumsum()
nth_frequency=df["Frequency"].sum()
n=nth_frequency/2
for i in range (0,6):
if df["cum_sum"][i]>n:
break
cf=df["cum_sum"][i-1]
l=df["LCB"][i]
h=(df["LCB"][1]-df["LCB"][0])
f=df["Frequency"][i]
MEDIAN=(l+(h/f)*(n-cf))
print("The Median is =",MEDIAN)

In [ ]: # Mode of Group Data


import pandas as pd
df=pd.read_excel("file_4.xlsx")
df[["Lower","Upper"]]=df["class_interval"].str.split("-",expand=True)
df["LCB"]=df["Lower"].astype("float")-0.5
df["UCB"]=df["Upper"].astype("float")+0.5
fm=df["frequency"].max()
i=df[df["frequency"]==fm].index[0]
l=df["LCB"][i]
h=(df["LCB"][1]-df["LCB"][0])
f1=df["frequency"][i-1]
f2=df["frequency"][i+1]
mode=l+((fm-f1)/(fm-1)+(fm-f2))*h
print("The Mode is =",mode)

In [ ]: ​

localhost:8888/notebooks/Untitled2.ipynb 1/1

You might also like