利用 pandas 自动合并 excel 单元格

代码比较简洁

 df = pd.DataFrame({
        "animal": ("horse", "horse", "dog", "dog"),
        "color": ("black", "white", "grey", "black"),
        "name": ("Blacky", "Wendy", "Rufus", "Catchy")
    })

    index = df.columns.to_list()
    df = df.set_index(index)
    df.to_excel("demo.xlsx")

效果展示

posted @ 2023-10-18 17:32  vx_guanchaoguo0  阅读(175)  评论(0编辑  收藏  举报