【发布时间】: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 文件
【问题讨论】:
我需要将 pandas 数据帧(在我的例子中为 df_new)写入一个包含一些公式的 xlsb 文件。我卡在下面的代码上,不知道下一步该怎么做:
with open_workbook('NiSource SLA_xlsb.xlsb') as wb:
with wb.get_sheet("SL Dump") as sheet:
谁能建议我如何将数据帧写入 xlsb 文件
【问题讨论】:
您可以尝试将 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')
将路径更改为您希望输出到的任何位置,并将文件名更改为您希望输出的名称。让我知道这是否有效。
【讨论】: