Python Forum
pandas pivot table: How to find count for each group in Index and Column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pandas pivot table: How to find count for each group in Index and Column
#1
I am new to pivot table. I just want the count of each Age Grp by Mth. I tried

pivot1=pd.pivot_table(df,index=[ "Age Grp"], columns=["Mth"], values=["Age Grp"], aggfunc=pd.Series.nunique)
but get ValueError: Grouper for 'Age Grp' not 1-dimensional

DF

 |Age Grp | Mth  | 
 | 0-4       |  1   |  
 | 5 -9      | 5    |  
 | 0-4       | 10   | 
 | 10-14    | 5  |  
Desired Outcome


     Mth    |  1    | 5    | 10    |
 |Age Grp |                         |
 | 0-4       |  1    |   0  | 1     |
 | 5 -9      | 0     |   1  | 0     |
 | 10-14    |  0   |   1  | 0     |
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need Help! Pandas EXCEL PIVOT psb3958 1 183 Nov-13-2022, 10:37 PM
Last Post: deanhystad
  Row Count and coloumn count Yegor123 4 265 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 248 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  Basic Pandas, obtaining a value from column and row JamesOzone 2 439 Jun-30-2022, 07:16 PM
Last Post: jefsummers
  group by create pivot table python dawid294 1 452 Jun-22-2022, 06:13 PM
Last Post: Larz60+
  df column mean and count of unique SriRajesh 0 510 May-07-2022, 08:19 AM
Last Post: SriRajesh
  df column aggregate and group by multiple columns SriRajesh 0 459 May-06-2022, 02:26 PM
Last Post: SriRajesh
  Removing the index column from df bnadir55 7 841 Apr-05-2022, 02:49 PM
Last Post: snippsat
  sqlalchemy could not find table 3lnyn0 4 2,011 Mar-30-2022, 12:36 PM
Last Post: Larz60+
  Float Slider - Affecting Values in Column 'Pandas' planckepoch86 0 698 Jan-22-2022, 02:18 PM
Last Post: planckepoch86

Forum Jump:

User Panel Messages

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