Apply styles while exporting to 'xlsx' in pandas with XlsxWriter

前端 未结 4 1102
刺人心
刺人心 2020-12-15 08:49

I use the .to_excel method of pandas to write a DataFrame as an Excel workbook. This works nice even for multi-index DataFrames as index cells become merged. When using the

4条回答
  •  醉梦人生
    2020-12-15 09:27

    Is there any way to do so

    Currently no. There isn't a formatting mechanism like that in Pandas for formatting the Excel output (apart from a few hard-coded formats).

    However, even if it was XlsxWriter doesn't currently support formatting cells after data is added. It is on TODO list.

    Update:

    As a workaround I recommend getting a reference to the underlying workbook and worksheet and overwriting any cells that you wish to be formatted with the same data from the Pandas dataframe and a XlsxWriter format.

    See Working with Python Pandas and XlsxWriter.

提交回复
热议问题