0

hi I am simply trying to save a dataframe to an excel (xlsx) and while I am able to save the data it seems its deleting other tabs. The tab I am pasting to already exists in the excel sheet so I don't need to add it. codes I have used are below

I came across quite a few similar questions on SO but didn't quite get the answer. could someone help plz? it just needs to go to the top left of the sheet i.e. row 0, column 0

    from openpyxl import load_workbook
    writer = pd.ExcelWriter('/Users/prasadkamath/PycharmProjects/Pk/tryexcel.xlsx', engine='openpyxl')
    PK_comb_updated.to_excel(writer, sheet_name='pk')
    writer.save()
TRex
  • 445
  • 5
  • 14
  • Does this help? https://stackoverflow.com/questions/13381384/modify-an-existing-excel-file-using-openpyxl-in-python – user1558604 Dec 09 '19 at 16:41
  • not sure it does tbh, I just have a simple df in my editor that I need to paste to an existing tab in excel. – TRex Dec 09 '19 at 20:05
  • writing a file generally overwrites the file. It may make sense to read the whole excel file, and then re-write it with your changes. – user1558604 Dec 09 '19 at 20:07

0 Answers0