简体   繁体   中英

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.

So far I have only seen documentation to write a dataframe with pandas. Is this the way to go? If so, I then will make a dataframe only containing that one variable.

What is the best and easiest way to go forward here?

One option is doing something like this using pandas dataframe and passing only the variable to the 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM