0

how to get the multiple aggregate function over a pivot table of all the columns not by individual columns over the pivot table. here is my pivot table

kpi_date     2019-01-01  2019-01-02     ...      2019-01-16  2019-01-17
ssaname                                 ...                            
Bangalore         43029       40038     ...           37599       39125
Belgaum            6975        6554     ...            7172        7274
Bellary            7163        6751     ...            7221        7103
Bidar              1603        1466     ...            1759        1693
Bijapur            4534        4283     ...            5022        4968
Chikmagalur        9177        8304     ...            5723        7442
Davangere          1949        1810     ...            2402        2368
Gulbarga           4265        4014     ...            4573        4504
Hassan             4898        4632     ...            4914        5027
Hubli              8974        8265     ...            9145        9169
Karwar            10059        9581     ...           10097       10345
Kodagu             7461        6838     ...            7422        7253
Kolar              2991        2698     ...            2793        2833
Mandya             1418        1317     ...            1386        1357
Mangalore         24765       23398     ...           24890       24993
Mysore             8774        7867     ...            7598        8107
Raichur            4271        4003     ...            4489        4391
Shimoga            8738        8097     ...            8791        8833
Tumkur             2612        2431     ...            2549        2560

I want sum,mean,max for columns from 2019-01-01 to 2019-01-17

1
  • Possible duplicate of this post Commented Jan 18, 2019 at 5:39

1 Answer 1

1

Using agg

df.agg(['mean','sum','max'])
         2019-01-01     2019-01-02     2019-01-16     2019-01-17
mean    8613.473684    8018.263158    8186.578947    8386.578947
sum   163656.000000  152347.000000  155545.000000  159345.000000
max    43029.000000   40038.000000   37599.000000   39125.000000

If need all values using stack

df.stack().agg(['max','mean','min'])
max     43029.000000
mean     8301.223684
min      1317.000000
dtype: float64

If need all row

df.T.agg(['mean','sum','max'])
Sign up to request clarification or add additional context in comments.

8 Comments

Not for colum , i want mean,max,sum for a row
df.agg(['mean','sum','max'], axis=1) This would do it too.
@AmitAmola This is not working as it says TypeError: ("'list' object is not callable", 'occurred at index Bangalore')
@srimannarayana is T work for you ? if so , would you like up-vote and accept ? :-)
@ W-B works again , but i am getting only the mean/max/sum values not the actual columns again i had to go for merge.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.