3

I am using the .to_excel method in pandas to write dataframe in an excel file. However i want to change the default formatting. The answer at Apply styles while exporting to 'xlsx' in pandas with XlsxWriter helps with the basic formatting.

However i want to change the cell background color for the header cells so I tried

import pandas.core.format
header_style_backup = pandas.core.format.header_style
pandas.core.format.header_style = {"font": {"bold": True"},
                                   "borders": {},
                                   "pattern": {"bg_color": "green"},
                                   "alignment": {"horizontal": "left", "vertical": "top"}}

However the "bg_color" does not show up in the output xlsx file. Is there some other way of specifying this?.

Or in general can i change the background colour for pandas exported dataframes into xlsx with xlsxwriter?

Community
  • 1
  • 1
pd321
  • 641
  • 6
  • 13

0 Answers0