我有以下数据框并想将其转换为 HTML
Limit Status Warning 3M AVG
VAR1 1.20 1.21216 1.11 1.21235
VAR2 0.82 0.63075 0.75 0.593295
VAR3 0.38 0.376988 0.35 0.376988
VAR4 0.17 0.126987 0.14 0.12461
我想按行格式化这个数据框,这样:
- 如果
Status
超过Warning
整行变成黄色高亮,如果超过Limit
整行变成红色高亮 - 行
VAR2
并VAR3
具有“{:.2%}”格式VAR1
并VAR4
具有“{:.2f}”
我已经深入研究了 pandas 文档并尝试了几种方法,但我无法完成上述所有任务
如果您能提供帮助,我将不胜感激,因为我相信对于许多熊猫用户来说,明智地格式化数据框行是一个挑战。
编辑1:我尝试了以下代码:
df=df.transpose()
df.style.format("{:.2%}").format({"VAR1":"{:.2f},"VAR4":"{:.2f}"})
注意:通过转置数据框,可以更轻松地完成所有任务,但我无法将其转回其原始形状,因为它是样式器。