0

When working with the with open method in Python I was expecting to just be able to write the data once and re open it.

I am using a for loop that involves me reopening the file to write another row in a excel file. I can write one but the second it reopens it just overwrites the row.

How do I save the row and have it re open and create a new row?

with pd.ExcelWriter("schoolsheet.xlsx", mode="a", if_sheet_exists="overlay") as writer:
    print("made it here")
    df.to_excel(writer)
    print("concludes writing to file")
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Crowbin
  • 1
  • 2
  • 2
    Does this answer your question? [append dataframe to excel with pandas](https://stackoverflow.com/questions/47737220/append-dataframe-to-excel-with-pandas) – mkrieger1 Apr 30 '23 at 08:15
  • There is the answer here: [How to write to an existing excel file without overwriting data (using pandas)?](https://stackoverflow.com/questions/20219254/how-to-write-to-an-existing-excel-file-without-overwriting-data-using-pandas) – Adrien Riaux Apr 30 '23 at 08:21

0 Answers0