6

How can I set different background color and font for some rows or columns when exporting a pandas DataFrame to Excel?

1 Answer 1

7

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.