我正在将一个熊猫数据帧导出为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">')虽然我可以分别更改列标题文本颜色和背景颜色,但我不能同时更改这两种颜色。有没有更好的方法来实现这一点,这样我就可以同时改变文本颜色和背景颜色,而不是只改变其中之一?谢谢!
发布于 2021-08-19 11:57:44
这会起作用的-
> example_df.to_html(index=False).replace('<th>','<th style =
> "background-color: royalblue; color: white">')https://stackoverflow.com/questions/64904147
复制相似问题