Fill the pd data frame on an existing excel sheet (using openpyxl v2.3.2)

I want to populate some pandas data frames in an existing file . I followed these instructions: How to write to an existing excel file without overwriting data (using pandas)? via:

  from openpyxl import load_workbook
  import pandas as pd
  import numpy as np

  book=load_workbook("excel_proc.xlsx")
  writer=pd.ExcelWriter("excel_proc.xlsx", engine="openpyxl")
  writer.book = book
  writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
  data_df.to_excel(writer, sheet_name="example", startrow=100, startcol=5, index=False)
  writer.save()

However, existing sheets will be deleted, an “approximate” sheet is created and only df will be integrated in a specific place. What have I done wrong? I want "data_df" to be written to an existing excel file in an existing "example" sheet, preserving other sheets and data.

thank

Df example:

data_df=pd.DataFrame(np.arange(12).reshape((2, 6)), index=["Time","Value"])
+4
source share
2 answers

. , load_workbook . openpyxl (conda install openpyxl). : v2.3.2 (python 35). : v2.4.0.

, . ​​ .

+2

xlwings, excel python.

, python , , .

+1

Source: https://habr.com/ru/post/1660787/


All Articles