我想你不能这样做。例如,参见this,它表示Excel可以处理文档的副本。
要将数据帧写入Excel文件,您可以使用pandas to_excel()
方法,如下所示:
your_dataframe.to_excel(output.xlsx')
使用Excel的更多细节的一个好模块是xlwt。你可以看到this tutorial,它解释了如何在很多例子中使用它。
我假设您不太关心速度,因为更新将实时发生并且对用户可见。我能想到实现这个目标的方法是使用win32 apis for com对象,在Windows上的Python中可用,通过win32com
包。为了与其他对象通信,我们通常需要win32com.client
包。
使用这个,写一个开放的excel书是相当简单的:
import win32com.client as win32
filename = "book.xlsx"
# Get a handle to excel:
excel = win32.gencache.EnsureDispatch('Excel.Application')
# Find open workbook with "filename" (which is the base name only)
wb = excel.Workbooks(filename)
# Set active sheet
ws = wb.Worksheets(1)
# We can access a single cell with "Cells":
ws.Cells(1,1).Value = "A1"
# Or multiple cells with a "Range" (note the strange tuple format of values)
ws.Range("C1:C3").Value =[("C1",), ("C2",), ("C3",)]
这个例子应该很简单,可以用来将你的pandas
data写入excel。但是,它需要您“手动”循环遍历不同的单元格并将它们写入Excel文档。