Is there a way to write multiple pandas dataframes to the same sheet using openpyxl engine?

li jun

I have done this but only the last dataframe was successfully written in the sheet. And I also found some samples to achive this using xlsxwriter engine,but how to do with openpyxl?

corralien

You can use ExcelWriter:

with pd.ExcelWriter('output.xlsx') as xlsx:
    df1.to_excel(xlsx, sheet_name='Sheet 1')
    df2.to_excel(xlsx, sheet_name='Sheet 1', startrow=len(df1) + 2)

enter image description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324288406&siteId=291194637