【发布时间】:2019-12-12 09:33:01
【问题描述】:
我使用以下代码突出显示了我的 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')
【问题讨论】: