在 Excel 中格式化 DataFrame

Formatting DataFrame in Excel

全部, 我从原始 csv 文件中生成了一些汇总统计数据。我还将此摘要保存到 excel 中。我现在需要通过格式化使这份报告看起来更漂亮。我知道将 CSS 样式应用于数据框,但无法将这些格式导出到 excel。 或者,我尝试使用 xlsxwriter 中的格式化功能来获得不同程度的成功。导出后是否可以格式化此数据框?

out.to_excel(writer, sheet_name='Dist-Market',startrow = 3 , startcol = 3)
def frmt_tbl(ws,rng):
    ws.set_column(rng, 30)

以下内容对我有所帮助,我想其他人也可能会觉得有用。

https://xlsxwriter.readthedocs.io/working_with_pandas.html

# Add some cell formats.
format1 = workbook.add_format({'num_format': '#,##0.00'})
format2 = workbook.add_format({'num_format': '0%'})

# Set the column width and format.
worksheet.set_column('B:B', 18, format1)

# Set the format but not the column width.
worksheet.set_column('C:C', None, format2)