如何在python pandas中将pandas数据帧写入xlsb文件

时间:2019-07-16 16:07:31

标签: python pandas

  

我需要将pandas数据框(以我的情况为df_new)写入具有某些公式的xlsb文件中。我停留在下面的代码上,不知道下一步该怎么做:

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

有人可以建议我如何将数据帧写入xlsb文件

1 个答案:

答案 0 :(得分:0)

您可以尝试将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')

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