【问题标题】:Merge rows based on value (pandas to excel - xlsxwriter) - addition根据值合并行(熊猫到 excel - xlsxwriter) - 加法
【发布时间】:2021-09-13 10:09:33
【问题描述】:

Following up this question

我想问一下我们是否可以合并多列中的行,即

根据@Dimitris Thomas 的回答,我将能够获得以下信息

想知道如何更新代码以获得:

谢谢

【问题讨论】:

    标签: pandas


    【解决方案1】:

    IIUC:

    首先:

    df=pd.read_excel('filename.xlsx')
    #read excel file in pandas
    

    通过set_index()to_excel() 尝试

    df.set_index(df.columns[:-1].tolist()).to_excel('filename.xlsx',header=None)
    #OR(Since you don't provide data as text so not sure which one should work)
    df.set_index(df.columns.tolist()).to_excel('filename.xlsx',header=None)
    

    【讨论】:

      猜你喜欢
      • 2020-07-27
      • 2019-07-20
      • 2018-09-05
      • 2017-09-15
      • 1970-01-01
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      相关资源
      最近更新 更多