vishal
vishal

Reputation: 269

How to write pandas dataframe into xlsb file in python pandas

I need to write pandas dataframe (df_new, in my case) into an xlsb file which has some formulas. I am stuck on the code below and do not know what to do next:

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

can anyone suggest me how to write dataframe into xlsb file

Upvotes: 2

Views: 8684

Answers (1)

oroy
oroy

Reputation: 92

You could try reading the xlsb file as a dataframe and then concating the two.

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')

Change the path to wherever you want the output to go to and change filename to what you want the output to be named. Let me know if this works.

Upvotes: 1

Related Questions