#中位数 defget_median(data): data = sorted(data) size = len(data) if size % 2 == 0: # 判断列表长度为偶数 median = (data[size//2]+data[size//2-1])/2 if size % 2 == 1: # 判断列表长度为奇数 median = data[(size-1)//2] return median
#众数(返回多个众数的平均值) defGet_Most(list): most=[] item_num = dict((item, list.count(item)) for item inlist) for k,v in item_num.items(): if v == max(item_num.values()): most.append(k) returnsum(most)/len(most)
#获取平均数 defGet_Average(list): sum = 0 for item inlist: sum += item returnsum/len(list)
#获取方差 defGet_Variance(list): sum = 0 average = Get_Average(list) for item inlist: sum += (item - average)**2 returnsum/len(list)
#获取n阶原点距 defGet_NMoment(list,n): sum=0 for item inlist: sum += item**n returnsum/len(list)