【问题标题】:How to write pandas dataframe into xlsb file in python pandas如何在 python pandas 中将 pandas 数据帧写入 xlsb 文件
【发布时间】:2019-07-17 13:11:27
【问题描述】:

我需要将 pandas 数据帧(在我的例子中为 df_new)写入一个包含一些公式的 xlsb 文件。我卡在下面的代码上,不知道下一步该怎么做:

with open_workbook('NiSource SLA_xlsb.xlsb') as wb:
    with wb.get_sheet("SL Dump") as sheet:

谁能建议我如何将数据帧写入 xlsb 文件

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    您可以尝试将 xlsb 文件作为数据框读取,然后将两者连接起来。

    import pandas as pd
    
    existingdf = pd.DataFrame()
    originaldf = pd.read_excel('./NiSource SLA_xlsb.xlsb'
    twodflist = [originaldf, df_new]
    existingdf = pd.concat(twodflist)
    existingdf.reset_index(drop = True)
    existingdf.to_excel(r'PATH\filename.xlsb')
    

    将路径更改为您希望输出到的任何位置,并将文件名更改为您希望输出的名称。让我知道这是否有效。

    【讨论】:

    • 但是在我的 NiSource SLA_xlsb.xlsb 中我有一些公式,所以如果我读取它并写入数据框,那么这些公式将无法正常工作。?
    • 哦,我在编辑之前写了答案。我将尝试提供一种输入方法,而无需摆脱公式。
    • 请。谢谢奥罗伊
    • 您可以尝试使用this 来查看它是否适用于您正在尝试做的事情。
    • 那个不是我要找的..你能告诉我另一种解决方案
    猜你喜欢
    • 2016-03-23
    • 2014-01-21
    • 2017-12-14
    • 1970-01-01
    • 2022-08-06
    • 2021-09-06
    • 1970-01-01
    • 2021-10-11
    • 2021-03-02
    相关资源
    最近更新 更多