【发布时间】:2021-03-02 08:59:18
【问题描述】:
我正在将 pandas 数据框导出为 html 表格,并且一直在尝试对最终表格中的标题列进行样式设置。这是我生成的示例数据框:
x = np.arange(0,100,5)
y = np.arange(0,20,1)
example_df = pd.DataFrame(x,y).head(10).reset_index()
example_df.columns = ['X Column', 'Y Column']
我已经能够使用以下代码编辑标题文本颜色:
example_df = example_df.to_html(index=False).replace('<th>','<th style = "color", "White">')
我还可以使用以下代码单独更改背景颜色:
example_df = example_df.to_html(index=False).replace('<th>','<th style = "background-color", "RoyalBlue">')
虽然我已经能够分别更改列标题文本颜色和背景颜色,但我无法同时更改两者。有没有更好的方法来实现这一点,以便我能够同时更改文本颜色和背景颜色,而不是在仅更改一个或另一个之间进行选择?谢谢!
【问题讨论】:
标签: python html pandas pdf-to-html