Python Forum
df column mean and count of unique
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
df column mean and count of unique
#1
Ji,
I have below df, and I want to group by coulmn2,column3 and calculate mean of other columns and unique count.

df:
col1 col2   col3  col4  col5
A1     A       x1    3     1
A2     A       x1    2     3
A3     A       x1    4     2
B2     P       x2    3     2
B2     P       x2    1     4
C6     Y       q2    1     4

[python]out:
col2   col3  col4  col5 count
A       x1    3     2      3
P       x2    2     3      2
Y       q2    1     4     1
I use below code but it does not give count

df.groupby(['col2','col3']).mean().reset_index()
But I am getting count.
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 266 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Row Count and coloumn count Yegor123 4 1,321 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  How to get unique entries in a list and the count of occurrence james2009 5 2,961 May-08-2022, 04:34 AM
Last Post: ndc85430
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,298 Oct-23-2021, 04:35 AM
Last Post: JaneTan
Photo Creating column in python based on the other colums value count Bartek635 2 2,921 Apr-15-2021, 03:47 PM
Last Post: Bartek635
  How to compare two columns and highlight the unique values of column two using pandas shubhamjainj 0 4,280 Feb-24-2020, 06:19 AM
Last Post: shubhamjainj
  How to calculate unique rows column sum and percentage SriRajesh 4 3,454 Feb-12-2020, 02:21 PM
Last Post: SriRajesh
  Count of unique items based on condition JP_ROMANO 3 6,264 Dec-31-2018, 08:11 PM
Last Post: JP_ROMANO
  count unique values of a list with a list 3Pinter 2 4,854 Jul-05-2018, 11:52 AM
Last Post: 3Pinter

Forum Jump:

User Panel Messages

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