聚合数据的中位数

时间:2017-10-31 14:08:40

标签: python pandas

我汇总了一个像这样的数据框:

x_mined_median = df[(df.Confirmed == True) & (df.Type == "Mined")].groupby(['dat']).median()

(缩短的)结果如下:

            Confirmed      Amount
dat
2017-09-01       True  836.202740
2017-09-03       True  650.958904
2017-09-04       True  150.076712
2017-09-07       True  445.928767
2017-09-08       True  382.439041
2017-09-10       True  401.145205

有没有办法获得Amount列的中位数? (中位数的中位数?)

1 个答案:

答案 0 :(得分:1)

选择列Amount并获取median

x_mined_median = df[(df.Confirmed == True) & (df.Type == "Mined")].groupby(['dat']).median()

a = x_mined_median['Amount'].median()

替代解决方案:

x_mined_median = (df.loc[(df.Confirmed == True) & (df.Type == "Mined"), 'Amount']
                   .groupby(df['dat']).median())

a = x_mined_median.median()