如何使用字典使用Python熊猫数据框的背景渐变颜色设置样式

时间:2020-08-05 01:15:39

标签: python pandas dataframe dictionary styles

我有以下索引为“ NUM”的熊猫数据框:

enter image description here

字典值(列表)中的值是数据框中的索引。我想向单元格添加背景渐变颜色,例如,在“ R1”列颜色1到10,在“ R2”列颜色3到20,依此类推。

我想使用以下字典为单元格添加背景渐变颜色:

d =  {'R1': [1,2,3,4,5,6,7,8,9,10]
,'R2': [3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
,'R3': [7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]
,'R4': [11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]
,'R5': [17,18,19,20,21,22,23,24,25,26,27,28]
}

我希望这样的结果:

enter image description here

类似的问题出现在: How to style a Python Pandas Dataframe using dictionary

但是它会应用统一的颜色。

谢谢。

0 个答案:

没有答案