I would like to create an excel file where one of the sheets is filled with calculated values and titles that are associated with them that would look like this :
In my case I have already inserted 2 previous worksheets that are files with a df using pandas.
My code goes as such :
writer = pd.ExcelWriter(Excel_file.xlsx", engine='xlsxwriter')
df1.to_excel(writer, sheet_name='Sheet1')
df2.to_excel(writer, sheet_name='Sheet2')
txt1 = str('TITLE 1')
txt2 = str('TITLE 2')
...
Value1 = 30
Value2 = 45
Value3 = 50
This works without a problem
I then tried adding the new sheet with the wanted information using 2 different ways
1 :
txt1.to_excel(writer, sheet_name='sheet3', startrow=0, startcol=0)
txt2.to_excel(writer, sheet_name='sheet3', startrow=1, startcol=0)
...
Value1.to_excel(writer, sheet_name='sheet3', startrow=1, startcol=1)
...
writer.save()
But this gave me this error message - AttributeError: 'str' object has no attribute 'to_excel'
2 :
worksheet = writer.sheets['sheet3']
worksheet.write(0, 0, txt1)
worksheet.write(1, 0, txt1)
...
worksheet.write(1, 1, Value1)
...
writer.save()
But this gave me this error message - KeyError: 'sheet3'