【问题标题】:Color Specific Headers in Pandas DataFramePandas DataFrame 中的颜色特定标题
【发布时间】:2021-01-05 21:40:59
【问题描述】:

我想在数据框中设置特定标题的背景颜色

这是原始数据框:

这就是我想要的:

到目前为止,我已经尝试过这段代码,但它不起作用:

df1.style.set_table_styles(
       [{
           'selector': 'th',
           'props': [('background-color', 'red')]
       }])

【问题讨论】:

标签: python pandas dataframe


【解决方案1】:

这应该对你有帮助!

import xlwings as xw
df1.to_excel("file.xlsx",index=False,header=False)
wb = xw.Book("file.xlsx")

# color is set with an rgb value 
wb.sheets['Sheet 1'].range('A').color = (169,169,169)

这基本上是写入 excel 广告,然后根据需要更改格式。您可以将颜色更改为您想要的任何 RGB 值。

【讨论】:

    猜你喜欢
    • 2017-11-13
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    • 2014-12-12
    • 2016-02-24
    • 2017-05-17
    相关资源
    最近更新 更多