Search code examples
pythonpandasdescribe

How to use customized describe function with a grouping variable to get statistics by group?


I was trying to get descriptive stats for a particular variable, by a grouping variable. I wanted more percentile values in the output than the describe function gives by default.

I tried the following code:

df.groupby('city')['population'].describe([0.01,0.05,0.25,0.50,0.75,0.90,0.95,0.99])

It gives an error: describe() takes 1 positional argument but 2 were given


Solution

  • What you should do -- calling the function properly

    df.groupby('a')['b'].describe(percentiles=[0.01,0.05,0.25,0.50,0.75,0.90,0.95,0.99])