Code python

Flatten Pandas DataFrame after Aggregate

Kontext Kontext visibility 881 comment 0 access_time 2 years ago language English

descriptionCode description

In code snippet Pandas DataFrame Group by one Column and Aggregate using MAX, MIN, MEAN and MEDIAN, it shows how to do aggregations in a pandas DataFrame. This code snippet shows you how to flatten the DataFrame (multiindex) after aggregations. 

Sample output:

  category  value_max  value_min  value_mean  value_median
0        A         90          0          45            45
1        B         91          1          46            46
2        C         92          2          47            47
3        D         93          3          48            48
4        E         94          4          49            49
5        F         95          5          50            50
6        G         96          6          51            51
7        H         97          7          52            52
8        I         98          8          53            53
9        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