Python Forum
df column aggregate and group by multiple columns - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: df column aggregate and group by multiple columns (/thread-37160.html)



df column aggregate and group by multiple columns - SriRajesh - May-06-2022

Hi,
I have below df I want to calculate rank, age pos columns max, min, mean and group by Name, sub,school. I use can only calculate mean, but I want to calculate min, max at the same time.

df.groupby(['Name','sub','school'])['rank'].mean().reset_index()
Name sub  school rank  age  pos
A        Ma    s1      2       10    4
A        Ma    s1      1       13    5
A        Ma    s1      4       10    6
B        Soc   s2      3        8     2
B        Soc   s2      4        6     7
A        Ma    s3      1        4     7
C        Sci    s3      2        2     1
C        Sci    s2      1        4     9