如何使用Python Pandas/XLSX Writer将数据与数据之间的边界设置为Excel

发布于 2025-01-28 12:12:32 字数 252 浏览 4 评论 0原文

我正在尝试与Python Pandas的边界一起格式化Excel表格,但没有运气,任何人都可以提供帮助。

我有这样的数据:

“在此处输入映像”

我希望以这种格式:

”在此处输入图像描述”

I am trying to format the excel sheet with the borders with python pandas, but no luck, can anyone please assist.

I have data like this:

enter image description here

I want this in this format:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假面具 2025-02-04 12:12:32

它并不简单,您必须遍历数据框架,然后将格式添加到每个单元格中。

cell_format = workbook.add_format()
cell_format.set_border()
for col_num, col in enumerate(df.columns.values):
    for row_num, value in enumerate(df[col].values):
        worksheet.write(row_num + 1, col_num + 1, value, cell_format)

It is not straightforward, You have to iterate through the dataframe and add the format to each cell.

cell_format = workbook.add_format()
cell_format.set_border()
for col_num, col in enumerate(df.columns.values):
    for row_num, value in enumerate(df[col].values):
        worksheet.write(row_num + 1, col_num + 1, value, cell_format)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文