![](/img/trans.png)
[英]How to write to an existing excel file without overwriting data (using pandas)?
[英]How do I write data to an existing file in Excel using Pandas?
我使用以下代碼讀取 file_1 中的數據,然后將其寫入新的 file_2。
import pandas as pd
inventory = pd.read_excel('file_1.xlsx', skiprows=3)
inventory.to_excel('file_2.xlsx')
file_2 每次都是新創建的文件。 如何在不清除包含數據的其他選項卡的情況下將數據寫入現有文件中的特定選項卡?
ExcelWriter
可用於 append 到現有的 Excel 文件,使用mode='a'
。 使用sheet_name
參數指定工作表名稱。
with pd.ExcelWriter('file_2.xlsx', mode='a') as writer:
inventory.to_excel(writer, sheet_name='Sheet_name_1')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.