Code python

Pandas DataFrame Group by one Column and Aggregate using MAX, MIN, MEAN and MEDIAN

Kontext Kontext visibility 1,288 comment 0 access_time 2 years ago language English

descriptionCode description

This code snippet provides one example of grouping a pandas DataFrame by one column and then aggregating on multiple columns using different functions including max, min, mean and median

We pass in a dictionary for each column that needs to be aggregated: the key is the column name, and the value is a list of aggregation functions supported by pandas DataFrame.  The result DataFrame will have multiple levels as following output shows:

Sample output:

         value
           max min mean median
category
A           90   0   45     45
B           91   1   46     46
C           92   2   47     47
D           93   3   48     48
E           94   4   49     49
F           95   5   50     50
G           96   6   51     51
H           97   7   52     52
I           98   8   53     53
J           99   9   54     54

fork_rightFork
more_vert
copyright This page is subject to Site terms.
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts