I have a data frame with 2-level indexed columns (sample data below):
metric grp Avg P95
mean ci_low ci_up mean ci_low ci_up
0 a CONTROL 8.202862 8.100596 8.306985 17.122063 16.832979 17.400000
1 a EXPERIMENT 8.243680 8.141428 8.351050 16.709375 16.383333 17.043500
2 a diff 0.040819 -0.102122 0.185837 -0.412688 -0.855854 0.050104
3 a rel_diff 0.005016 -0.012299 0.022944 -0.024022 -0.049377 0.002982
4 b CONTROL 15.513669 15.316762 15.720606 31.893576 31.357300 32.600350
5 b EXPERIMENT 15.486001 15.293760 15.672843 31.317389 30.808775 31.839000
6 b diff -0.027668 -0.300167 0.251497 -0.576186 -1.450138 0.223063
7 b rel_diff -0.001740 -0.019249 0.016368 -0.017967 -0.044785 0.007031
Result I’d like to produce:
- create a new column in format of
mean [cl_low, cl_up]
for each level-1 columnAvg
,P95
- for
rel_diff
rows, reformat all columns as percentages, e.g.:0.005016 --> 0.5%
. - for rest rows, round all columns to 3rd digit
What is the pythonic way to do this? Thanks in advance for tips!