Calculating Median using Groupby by using QUANTILE

User 2568 | 7/8/2016, 8:00:33 AM

groupby doesn't have a median aggregator, however I can write instead:

xx = train.groupby(features, {"Pred2": gl.aggregate.QUANTILE(col, 0.5)})

The problem is result is a single element in a list so I then need to write:

xx[col] = xx[col].apply(lambda lst:lst[0])

I understand that normally the second arg to QUANTILE is a list of quantiles, but in this case I did not give a list, just 0.5 and so it's not unreasonable expected the result to not be a list. Also, just as you have both AVG and MEAN, why not support MEDIAN as a short cut.

Comments

User 91 | 7/8/2016, 3:23:55 PM

That sounds like a great feature request. We should add MEDIAN as a short cut.


User 2568 | 7/8/2016, 7:58:43 PM

Great, and please ensure it returns a float not a list