Ugur
Ugur

Reputation: 2044

Median of aggregated data

I have aggregated a dataframe like so:

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

The (shortened) result is this:

            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

Is there a way to get the median of the Amount column? (A median of the median?)

Upvotes: 1

Views: 344

Answers (1)

jezrael
jezrael

Reputation: 862911

Select column Amount and get median:

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

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

Alternative solution:

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

a = x_mined_median.median()

Upvotes: 1

Related Questions