简体   繁体   English

Python pandas:将变量写入现有工作表中的 excel 单元格

[英]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.

相关问题 Python Excel 在现有工作表中写入 DataFrame - Python Excel write a DataFrame in an existing sheet 将值写入python中pandas中工作表中的特定单元格 - Write values to a particular cell in a sheet in pandas in python 编写大熊猫数据框值,使其优于特定工作表中的特定单元格。 - Write pandas dataframe values to excel to specific cell in a specific sheet. 读取Excel中的单元格值并使用python写入现有的Excel文件 - Reading a cell value in Excel and write into an othet existing Excel file with python Python:将数据框写入到现有的Excel中,其中包含带有图像的工作表 - Python: Write a dataframe to an already existing excel which contains a sheet with images 想要读取一个文件并使用 python 写入现有的 excel 表 - Want to read an a file and write to existing excel sheet using python "使用 python pandas 将现有的 excel 表附加到新的数据框" - Append existing excel sheet with new dataframe using python pandas 如何将 Python 数组写入单个 Excel 电子表格单元格 - How to Write Python array into a Single Excel Spread Sheet Cell Python Pandas 将 Excel 表单元格导入为 object 最后没有引号 - Python Pandas Import Excel sheet cell as object without quotes in the end Python Pandas - 如何在 Excel 工作表的特定列中写入 - Python Pandas - How to write in a specific column in an Excel Sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM