user3190746
user3190746

Reputation: 21

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). 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). The approach I'm using now with Openpyxl works, but is quite time-consuming. I'm wondering if there's another, faster approach to writing data to an existing Excel sheet? 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. Here are some of the resources I've read about this issue on:

Upvotes: 1

Views: 685

Answers (1)

Keith
Keith

Reputation: 4924

I would pull it in with pd.read_csv(), do manipulations then write with df.to_csv(). Do you need to keep it in the excel format? I tend to find that this is not worth it.

Upvotes: 0

Related Questions