gpt4 book ai didi

python - 在 Excel 中设置 DataFrame 格式

转载 作者:行者123 更新时间:2023-12-01 08:01:37 26 4
gpt4 key购买 nike

所有,我从原始 csv 文件中生成了一些汇总统计数据。我还将这个摘要保存到 Excel 中。我现在需要通过格式化使该报告看起来更漂亮。我知道将 CSS 样式应用于数据框,但无法将这些格式导出到 Excel。另外,我尝试使用 xlsxwriter 中的格式化功能,取得了不同程度的成功。导出后有没有办法格式化此数据框?

table

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)

关于python - 在 Excel 中设置 DataFrame 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55707356/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com