Python Forum
df column aggregate and group by multiple columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
df column aggregate and group by multiple columns
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 223 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Converting column of values into muliple columns of counts highland44 0 205 Feb-01-2024, 12:48 AM
Last Post: highland44
  Python and pandas: Aggregate lines form Excel sheet Glyxbringer 12 1,697 Oct-31-2023, 10:21 AM
Last Post: Pedroski55
  How to check multiple columns value within range SamLiu 2 1,104 Mar-13-2023, 09:32 AM
Last Post: SamLiu
  How to combine multiple column values into 1? cubangt 15 2,634 Aug-11-2022, 08:25 PM
Last Post: cubangt
  How to move multiple columns to initial position SriRajesh 4 1,375 Jul-02-2022, 10:34 AM
Last Post: deanhystad
  Reshaping a single column in to multiple column using Python sahar 7 1,969 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  Transform 3 Columns into Single Column DaveG 8 1,801 Apr-04-2022, 08:42 AM
Last Post: Pedroski55
  Split single column to multiple columns SriRajesh 1 1,290 Jan-07-2022, 06:43 PM
Last Post: jefsummers
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,229 Oct-23-2021, 04:35 AM
Last Post: JaneTan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020