我用黄色突出显示了我的df的最大值,代码如下:
def highlight_max(s):
is_max = s == s.max()
return ['background-color: yellow' if v else '' for v in is_max]
pivot_p.style.apply(highlight_max)
但现在我要突出显示每列的5个最大值。我尝试了以下代码,但不起作用:
def highlight_large(s):
is_large = s == s.nlargest(5)
return ['background-color: yellow' if v else '' for v in is_large]
pivot_p.style.apply(highlight_large)
错误:
ValueError: ('Can only compare identically-labeled Series objects', 'occurred at index %_0')
您可以尝试:
完整示例:
输出:
相关问题 更多 >
编程相关推荐