我有以下代码将数据框转储到 HTML 中的表中,以便根据 seaborn 的颜色图对results
其中的列进行着色。TIME_FRAMES
import seaborn as sns
TIME_FRAMES = ["24h", "7d", "30d", "1y"]
# Set CSS properties for th elements in dataframe
th_props = [
('font-size', '11px'),
('text-align', 'center'),
('font-weight', 'bold'),
('color', '#6d6d6d'),
('background-color', '#f7f7f9')
]
# Set CSS properties for td elements in dataframe
td_props = [
('font-size', '11px')
]
cm = sns.light_palette("green", as_cmap=True)
s = (results.style.background_gradient(cmap=cm, subset=TIME_FRAMES)
.set_table_styles(styles))
a = s.render()
with open("test.html", "w") as f:
f.write(a)
由此,我得到警告:
/python3.7/site-packages/matplotlib/colors.py:512:RuntimeWarning:在 less xa[xa < 0] = -1 中遇到无效值
而且,正如您在下图中看到的那样,列30d
并1y
没有正确呈现,因为它们有 NaN。我怎样才能做到这一点,以便忽略 NaN 并且仅使用有效值呈现颜色?将 NaN 设置为 0 不是一个有效的选项,因为这里的 NaN 本身就有意义。