0

I am trying to write to a single Excel worksheet but the program is creating a new worksheet for each new row I am appending:

applicationList = []
i = 0
maxLengthList = 6
while len(applicationList) < maxLengthList:
    application = input("Enter the application name: ")
    applicationList.append(application)
    # Convert the dataframe to an XlsxWriter Excel object.
    output_df = df.query('Name=="%s"' % applicationList[i])
    i += 1

    with pd.ExcelWriter("Test.xlsx", mode="a") as writer:
        output_df.to_excel(writer)

Can someone show me how to write all rows to the same work sheet so that there will be 6 rows in one worksheet instead of 1 row in 6 worksheets?

  • 1
    Do any of the answers here help you: https://stackoverflow.com/q/38074678/9987623 – AlexK Mar 29 '21 at 01:05
  • 1) Append to csv instead. 2) Append to a `output_df`, output `output_df` to excel after the loop. – Ynjxsjmh Mar 29 '21 at 04:46
  • Helper function from https://stackoverflow.com/questions/38074678/append-existing-excel-sheet-with-new-dataframe-using-python-pandas helped me fix my issue. – Christian Townsend Mar 29 '21 at 22:55

0 Answers0