【问题标题】:pandas: split merged header from excel熊猫:从excel中拆分合并的标题
【发布时间】:2021-12-02 15:25:04
【问题描述】:

我有一个这样的合并标题的 excel 文件

我想要的是像这样使用熊猫的标题

我尝试使用此解决方案: https://stackoverflow.com/a/27424102/12934577

但它返回 sequence item 0: expected str instance, float found

【问题讨论】:

    标签: python excel pandas


    【解决方案1】:

    您可能需要使用str,而不是像在那个答案中一样:

    df.columns = df.iloc[0:2].apply(lambda x: '.'.join([str(y) for y in x if y]), axis=0)
    

    【讨论】:

    • 谢谢,但是 a,b 和 c 下方的 NaN 值(因为它被合并了)仍然存在它只是变换了“_”
    猜你喜欢
    • 2023-02-21
    • 1970-01-01
    • 2020-04-08
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    相关资源
    最近更新 更多