pandas groupby percentile 1

pandas groupby percentile

# 50th Percentile
def q50(x):
    return x.quantile(0.5)

# 90th Percentile
def q90(x):
    return x.quantile(0.9)

my_DataFrame.groupby(['AGGREGATE']).agg({'MY_COLUMN': [q50, q90, 'max']})

Here is what the above code is Doing:
1. Grouping the dataframe by the AGGREGATE column
2. Aggregating the MY_COLUMN column by the following functions:
a. q50
b. q90
c. max

Similar Posts