[英]What's the fastest way to write data to an existing Excel sheet using Python?
I'm working on a Windows 10 machine (win32, Python 3.8.2).我正在使用 Windows 10 机器(win32、Python 3.8.2)。 I'm using pandas to read in two excel files as dataframes, then using Openpyxl to write data to an existing Excel file (that has data and formulas already in the sheet).
我正在使用 pandas 读取两个 excel 文件作为数据帧,然后使用 Openpyxl 将数据写入现有的 Excel 文件(已经在表格中)。 The approach I'm using now with Openpyxl works, but is quite time-consuming.
我现在对 Openpyxl 使用的方法有效,但非常耗时。 I'm wondering if there's another, faster approach to writing data to an existing Excel sheet?
我想知道是否有另一种更快的方法将数据写入现有的 Excel 表? I feel like this could possibly be done by appending my dataframe(s) to the existing Excel sheet, but I've read online that the sheet I am writing to would have all of its data erased before my data is written to it.
我觉得这可以通过将我的数据帧附加到现有的 Excel 表来完成,但我在网上读到我正在写入的表会在我的数据写入之前删除所有数据。 Here are some of the resources I've read about this issue on:
以下是我读过的有关此问题的一些资源:
How to write to an existing excel file without overwriting data (using pandas)? 如何在不覆盖数据的情况下写入现有的 excel 文件(使用熊猫)?
Append existing excel sheet with new dataframe using python pandas Append existing excel sheet with new dataframe using python pandas
https://datascience.stackexchange.com/questions/46437/how-to-write-multiple-data-frames-in-an-excel-sheet https://datascience.stackexchange.com/questions/46437/how-to-write-multiple-data-frames-in-an-excel-sheet
I would pull it in with pd.read_csv(), do manipulations then write with df.to_csv().我会用 pd.read_csv() 把它拉进去,做操作然后用 df.to_csv() 写。 Do you need to keep it in the excel format?
需要保持excel格式吗? I tend to find that this is not worth it.
我倾向于发现这是不值得的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.