sriman narayana
sriman narayana

Reputation: 359

Multiple aggregate function over a pivot table

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

Upvotes: 0

Views: 370

Answers (1)

BENY
BENY

Reputation: 323226

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'])

Upvotes: 1

Related Questions