# Summary statistics by category using Python

I have a datset with Scores and Categories and I would like to calculate the summary statistics for each of these categories. The data look something like this:

Category    Score
AAAA        1
AAAA        3
AAAA        1
BBBB        1
BBBB        100
BBBB        159
CCCC        -10
CCCC        9


What I would then like would be something like this

Category    Count   Mean   Std   Min   25%   50%   75%   Max
AAAA
AAAA
AAAA
BBBB
BBBB
BBBB
CCCC
CCCC


I have been looking at using pandas with a combination of both .groupby() and .describe() like this

df.groupby('Category')['Score'].describe()


and this almost looks like what I want but when I come to view this as a Dataset, all of the stats are in the index. I would like the data to be in the form of a table so I can output it and create a visualization off of the back of it.

Any ideas?

Thanks

• Could you clarify your question? It's not very clear what you are trying to achieve... What is wrong with df.groupby('Category')['Score'].describe()? – MaxU Aug 15 '17 at 12:05
• Apologies @MaxU. Hopefully I have clarified now :-) – Taylrl Aug 15 '17 at 12:31

In [80]: df.groupby("Category")['Score'].describe().reset_index()