Advertisement

Pandas------处理multi-index表头 - 处理Multi-column表头

阅读量:

Pandas ------ 向 Excel 文件中写入含有 multi-index 和 Multi-column 表头的数据

  • 引言
  • 正文

引言

《pandas向已经拥有数据的Excel文件中插入多表头数据的方法》这篇文章详细讲解了如何利用pandas将多个带有独立列标题的数据插入到一个已有的Excel文件中。

正文

复制代码
    import pandas as pd
    
    
    df1 = pd.DataFrame([['a', 'b'], ['c', 'd']],
                   index=[['row 1', 'row 2'],],
                   columns=[['layer1', 'layer2'],
                            ['col 1', 'col 2']])
    df1.to_excel("output.xlsx")

执行完上述代码后,在代码存放目录中会发现一个名为 output.xlsx 的 Excel 文件

![在这里插入图片描述](https://ad.itadn.com/c/weblog/blog-img/images/2025-05-31/bgmhV18XTq6Ys02ePv7rMz

全部评论 (0)

还没有任何评论哟~