How can I set different background color and font for some rows or columns when exporting a pandas DataFrame to Excel?
1 Answer
https://pbpython.com/improve-pandas-excel-output.html has examples using xlsxwriter to customize the output file:
writer = pd.ExcelWriter('fancy.xlsx', engine='xlsxwriter')
df.to_excel(writer, index=False, sheet_name='report')
workbook = writer.book
worksheet = writer.sheets['report']
percent_fmt = workbook.add_format({'num_format': '0.0%',
'bold': True
#, 'bg_color': '#FFC7CE'
})
worksheet.set_column('L:L', 12, percent_fmt)
writer.save()