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
  Exploding multiple columns Mormolyce 2 2,646 Sep-07-2025, 02:13 PM
Last Post: Mormolyce
  Transform 3 Columns into Single Column DaveG 9 4,775 Mar-19-2025, 03:46 AM
Last Post: robbert23
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 2,875 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Converting column of values into muliple columns of counts highland44 0 1,270 Feb-01-2024, 12:48 AM
Last Post: highland44
  Python and pandas: Aggregate lines form Excel sheet Glyxbringer 12 7,676 Oct-31-2023, 10:21 AM
Last Post: Pedroski55
  How to check multiple columns value within range SamLiu 2 3,015 Mar-13-2023, 09:32 AM
Last Post: SamLiu
  How to combine multiple column values into 1? cubangt 15 9,435 Aug-11-2022, 08:25 PM
Last Post: cubangt
  How to move multiple columns to initial position SriRajesh 4 3,820 Jul-02-2022, 10:34 AM
Last Post: deanhystad
  Reshaping a single column in to multiple column using Python sahar 7 4,574 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  Split single column to multiple columns SriRajesh 1 2,420 Jan-07-2022, 06:43 PM
Last Post: jefsummers

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.