[英]Python pandas: Write variable to excel cell in existing sheet
I'm using python pandas to read a large dataset from excel. I then do some calculations and want to write a variable to a single cell in a existing excel file in an existing sheet.我正在使用 python pandas 从 excel 读取一个大数据集。然后我做了一些计算,并想将一个变量写入现有工作表中现有 excel 文件中的单个单元格。
So far I have only seen documentation to write a dataframe with pandas. Is this the way to go?到目前为止,我只看到了用 pandas 写一个 dataframe 的文档。这是通往 go 的路吗? If so, I then will make a dataframe only containing that one variable.
如果是这样,我将创建一个仅包含该变量的 dataframe。
What is the best and easiest way to go forward here?在这里转发 go 的最佳和最简单方法是什么?
One option is doing something like this using pandas dataframe and passing only the variable to the dataframe:一种选择是使用 pandas dataframe 执行类似的操作,并将变量仅传递给 dataframe:
with pd.ExcelWriter("tom_test.xlsx", mode="a", engine="openpyxl", if_sheet_exists='overlay') as writer:
test = pd.DataFrame([fkbareal_tot])
test.to_excel(writer, sheet_name="sheet 1", startrow=1, startcol=1, index=False, header=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.