Currently there is a median method on the Pandas\'s GroupBy objects.
Is there is a way to calculate an arbitrary percentile (s
I found another useful solution here
If I have to use groupby another approach can be:
def percentile(n):
def percentile_(x):
return np.percentile(x, n)
percentile_.__name__ = 'percentile_%s' % n
return percentile_
Using the below call, I am able to achieve the same result as the solution given by @TomAugspurger
df.groupby('C').agg([percentile(50), percentile(95)])