I used the following code to read data in file_1 then write that to a new file_2.
import pandas as pd
inventory = pd.read_excel('file_1.xlsx', skiprows=3)
inventory.to_excel('file_2.xlsx')
file_2 is a newly created file each time. How do I write the data to specific tab in an existing file without clearing out other tabs that contain data?
ExcelWriter
can be used to append to an existing Excel file using mode='a'
. Specify the sheet name with the sheet_name
parameter.
with pd.ExcelWriter('file_2.xlsx', mode='a') as writer:
inventory.to_excel(writer, sheet_name='Sheet_name_1')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.