python写入html文件带样式,使用pandas将数据帧写入html时应用样式映射
我想將pandas數據幀輸出到.html并應用樣式。文檔*給出了一個將負值顯示為紅色的示例。在import pandas as pd
import numpy as np
np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
axis=1)
df.iloc[0, 2] = np.nan
def color_negative_red(val):
"""
Takes a scalar and returns a string with
the css property `'color: red'` for negative
strings, black otherwise.
"""
color = 'red' if val < 0 else 'black'
return 'color: %s' % color
s = df.style.applymap(color_negative_red)
s
我可以用“to_html”方法輸出格式化的df嗎?從那個文檔**我看到有一個“formatters”選項,但我不知道如何在這種情況下應用它。在
以下是我如何編寫無格式df:
^{pr2}$
總結
以上是生活随笔為你收集整理的python写入html文件带样式,使用pandas将数据帧写入html时应用样式映射的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 检测html输入框是否一样,如何测试一个
- 下一篇: 学完计算机之后的感受,计算机教学心得心得