0

Colleagues, I have the following excel file. But, when I compile the program again, my data is overwritten. I'd like to put each results of the next compilations in a row. I've seen some examples with append, but I can not make it work. Could someone help me, please? !!

writer = pd.ExcelWriter('output.xlsx')

df = pd.DataFrame({'Function':[Output],'Circuit':[gates],'Cost':[cost]},)

df.to_excel(writer,'Sheet1')

writer.save()

1 Answers1

3

I guess there is no direct way to append rows to existing excel

Try this code, it may help

read your excel as dataframe

df1 = pd.read_excel('output.xlsx')

and your defined dataframe

df2 = pd.DataFrame({'Function':[Output],'Circuit':[gates],'Cost':[cost]})

then write both dataframe to excel

df1.to_excel(writer,startrow=0,index=False)
df2.to_excel(writer,startrow=len(df1)+1,header=False,index=False)
Geetha Ponnusamy
  • 497
  • 3
  • 15