将熊猫样式应用于多索引DataFrame

时间:2020-02-04 20:13:29

标签: python pandas apply styling multi-index

我正在处理以下数据:

pd.DataFrame(index=pd.MultiIndex.from_product((['Ch 1', 'Ch 2', 'Ch 3', 'Ch 4', 'Ch 5'], 
                                              ['Before Sunday', 'Sunday'])),
             data={'Metric 1': [11.428571428571429, 10.0, 25.571428571428573, 24.0, 15.285714285714286, 17.0, 96.0, 96.0, 20.571428571428573, 20.0],
                   'Metric 2': [8.866494655142857, 8.17326377, 27.335643895428568, 0.9523124709999999, 3.813590807428571, 2.7668162119999997, 23.037594747142858, 16.399421863, 20.066009883714287, 20.937331853],
                   'Metric 3': [1440.0, 1395.0, 1440.0, 1440.0, 1435.7142857142858, 1440.0, 1440.0, 1440.0, 1433.5714285714287, 1485.0],
                   'Metric 4': [9.539868914714285, 8.765852295, 28.187885563285715, 0.971623777, 4.003307316428571, 2.894219025, 26.31292695942857, 20.024459028, 23.00698147385714, 23.877707008],
                   'Metric 5': [46.54198155985715, 66.82155792100001, 8.295209672428571, 1.6969679169999998, 20.963911224285713, 26.843881458000002, 411.8365706348572, 1833.489529722, 333.562462153, 347.37641899]})

我对应用一种样式功能感兴趣,该功能将突出显示按索引的第一级分组的每一列中的较大值。

例如: enter image description here

我正在尝试从pandas.styling文档中复制此示例,但我不想突出显示每一列的最大值,而是要突出显示每一列中每个level-1组的最大值。

enter image description here

在此先感谢您的帮助。

0 个答案:

没有答案