Home > other >  Adopt the method of to_excel don't cover the original file
Adopt the method of to_excel don't cover the original file

Time:09-19

The pandas module data processing, with to_ecxel method to write process the results into the source file, the source file will be covered, adopt openpyxl function, can not cover the original file content, add sheet in file output processing results,

Examples are as follows:
 
The import openpyxl
The import pandas as pd

Path=r "C: \ Users \ John \ Desktop \ test XLSX"
Df=pd read_excel (path, index_col=None)
Result=df. Head ()

Excel_writer=pd. ExcelWriter (path, engine='openpyxl')
Book=openpyxl. Load_workbook (excel_writer. Path)
Excel_writer. Book=the book
Result. To_excel (excel_writer=excel_writer, sheet_name='test', the index=None)
Excel_writer. Close ()



CodePudding user response:

You use python first file a copy not have replication method

CodePudding user response:

 
Book=load_workbook (tag_file) # to write the existing table
Writer=pd. ExcelWriter (tag_file, engine='openpyxl')
Writer.=the book book
Writer. Sheets=dict ((ws. The title, ws) for ws in the book. Worksheets)
Totaldata. To_excel (writer, sheet_name='company', startcol=0,
While the startrow=0, the index=True, the header=True) # header=False said don't header
Writer. The save ()


So I can write an existing table
  • Related