[問題] Python字體上色卻無法顯示?哪邊錯了?
懇請Python高手指點一下哪邊錯了!?
下為提問的程式碼:
def color_negative_red(val):
color = 'red' if val > 1.2 else 'black'
return 'color: %s' % color
數值大於1.2呈現紅色
def color_negative_yellow(val):
color = 'yellow' if val > 1 else 'black'
return 'color: %s' % color
數值大於1呈現黃色
def color_negative_green(val):
color = 'green' if val > 0.8 else 'black'
return 'color: %s' % color
數值大於0.5呈現綠色
問題如下:
T3 = table[4].dropna(axis=1,how='all')
T3.columns = hdtt3
T3.style.applymap(color_negative_red,
subset=['POWER-DIFFERENCE']).applymap(color_negative_yellow,
subset=['POWER-DIFFERENCE']).applymap(color_negative_green,
subset=['POWER-DIFFERENCE'])
display(T3)
這樣子寫為何無法判斷把字體的顏色呈現出來?哪邊有錯?要怎麼修正?
判斷的定義:
數值大於1.2呈現紅色且數值大於1底色呈現黃色且數值大於0.5呈現綠色;其他為黑色。
我要達到如此效果如右圖連結:https://i.imgur.com/DtsHpBf.jpg
懇請指點<(_ _)>
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.224.49.75
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1515422968.A.441.html
※ 編輯: han999 (114.36.71.166), 01/10/2018 23:16:44
→
01/10 23:17,
6年前
, 1F
01/10 23:17, 1F
→
01/10 23:20,
6年前
, 2F
01/10 23:20, 2F
→
01/10 23:21,
6年前
, 3F
01/10 23:21, 3F
推
01/10 23:53,
6年前
, 4F
01/10 23:53, 4F
→
01/10 23:53,
6年前
, 5F
01/10 23:53, 5F
推
01/11 00:12,
6年前
, 6F
01/11 00:12, 6F
→
01/11 00:54,
6年前
, 7F
01/11 00:54, 7F
→
01/11 00:55,
6年前
, 8F
01/11 00:55, 8F
→
01/11 06:57,
6年前
, 9F
01/11 06:57, 9F
→
01/11 09:06,
6年前
, 10F
01/11 09:06, 10F
→
01/11 11:15,
6年前
, 11F
01/11 11:15, 11F
推
01/14 22:53,
6年前
, 12F
01/14 22:53, 12F
推
01/21 14:40,
6年前
, 13F
01/21 14:40, 13F
→
01/21 14:40,
6年前
, 14F
01/21 14:40, 14F
→
01/21 14:40,
6年前
, 15F
01/21 14:40, 15F
→
01/21 14:52,
6年前
, 16F
01/21 14:52, 16F
→
01/21 14:52,
6年前
, 17F
01/21 14:52, 17F
※ 編輯: han999 (1.160.208.123), 01/23/2018 22:30:07