程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Method of finding mode after Python grouping

編輯:Python

background

The average , Median and mode are commonly used statistical indicators to represent data level . When we want to compare the differences between different groups of data , Generally speaking, the average is used , But the average is susceptible to extremes , At this time, the median and mode are a better choice .

stay pandas in , We can use pivot_table Functions and groupby Function to find the grouping statistics . But they can't directly calculate the outstanding number . So here's the article . It's easy :

Method

df = pd.DataFrame({
'a':['A','A','A','A','B','B','B','B','B'],'b':[1,1,2,3,1,2,2,3,3]})
df
ab0A11A12A23A34B15B26B27B38B3
def mode1(x):
restult = np.mean(pd.Series.mode(x))
return restult
pd.pivot_table(dfssss,index="a",values="b",aggfunc=mode1)
baA1B2.5
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved