0

Sorry for this question. I am here for the first time. I have a problem with inserting the data frame into the existing sheet of Excel.

Please, could you show examples of how to do this?

Thank you for helping.

UPDATED:

I forgot to say I've already tried solutions with pd.to_excel - this solution deleted my other sheets in the workbook. And I've tried the solution with openpyxl.load_workbook - load_workbook doesn't work when I have formatting or colors or pivots into my workbook. Even if I have a clean workbook this solution is deleting my previous sheets.

  • 2
    https://stackoverflow.com/questions/20219254/how-to-write-to-an-existing-excel-file-without-overwriting-data-using-pandas – BigBen Mar 24 '21 at 15:04
  • 1
    https://stackoverflow.com/questions/42370977/how-to-save-a-new-sheet-in-an-existing-excel-file-using-pandas – BigBen Mar 24 '21 at 15:04
  • 1
    https://stackoverflow.com/questions/54186519/appending-pandas-dataframe-to-existing-excel-document – BigBen Mar 24 '21 at 15:04

1 Answers1

0

These questions might help.

Appending Pandas DataFrame to existing Excel document

How to write to an existing excel file without overwriting data (using pandas)?

How to save a new sheet in an existing excel file, using Pandas?

Good luck :)

  • Thank you for helping. But those articles I've already read and they haven't help me. For example, when I used this way: writer = pd.ExcelWriter(wk_path + save_file) #engines openpyxl or xlsxwriter no matter counts_os.to_excel(writer, sheet_name='test', startcol=1, startrow=1) writer.save() writer.close() I got a new sheet 'test' with deleting all of the previous sheets in my file. – trofim_from_russia Mar 25 '21 at 06:17
  • or, when I tried to use this way: import pandas from openpyxl import load_workbook book = load_workbook('Masterfile.xlsx') I got an error: Value must be a sequence @JLT – trofim_from_russia Mar 25 '21 at 06:30
  • The last way works the same as the first (with deleting other sheets). And the last way works when I only have a clear book without pivot tables and so on. – trofim_from_russia Mar 25 '21 at 06:47
  • @trofim_from_russia, you might want to use something different then panda's. I'm using OpenPyxl –  Sep 21 '21 at 12:44