[英]Using highlight_max and highlight_min from pandas.io.formats.style.Styler at the same time
[英]Combine bar chart and highlight when using Pandas Styler on the same column
有沒有辦法在 Pandas 的 DataFrame 中結合條形樣式器和高亮樣式器?
例如,我想用紅色突出顯示 NaN 值,但如果它不是 NaN,則會顯示綠色條。
Score
79 --> green bar
84 --> green bar
nan --> red highlight
目前,我只能使用highlight_null
或apply_map
來突出顯示 NaN 值,但不知道如何將它與pandas.io.formats.style.Styler.bar
結合起來
最后我可以先調用bar
function再applymap
結合起來
def style_zero(v, props=''):
return props if v == 0 or v == np.nan else None
df.style.bar(color='#5fba7d').applymap(style_zero, props='background-color:pink;color:red')
也許,它會幫助與我有同樣問題的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.