I have a Pandas dataframe as shown below:
Voice_Usage | Data_Usage | Revenue | Age | Segment
--------------------------------------------------
300 | 20 | 400 | 35 | 1
700 | 10 | 300 | 40 | 1
100 | 15 | 200 | 32 | 3
150 | 30 | 100 | 20 | 2
450 | 12 | 450 | 54 | 1
900 | 18 | 800 | 17 | 3
... ... ... ... ...
I want to derive a dataframe from the above dataframe where each Segment type will have all the variables in data frame and their statistical measures (min, max, mean).
The derived dataframe should be like:
Segment | Variables | Min | Max | Mean |
----------------------------------------
1 Voice_Usage 5 100 50
1 Data_Usage 0 50 30
1 Revenue 50 1500 300
1 Age 10 80 35
2 Voice_Usage 10 200 70
2 Data_Usage 10 90 50
2 Revenue 30 500 200
2 Age 15 60 25
3 Voice_Usage 5 100 500
3 Data_Usage 0 50 30
3 Revenue 50 1500 300
3 Age 10 80 35
...and so on.
How can I derive the second dataframe from the first one? I grouped by segment value with aggregating over other variables but that did not work. I need to make it generic for n no. of variables of the dataframe.