I want to print a list to the excel file with for loop. For example, a loop runs 7 times and a list, that is free at the beginning, fills with some numbers while the loop running. After that, I tried to print this list to excel:

df = pd.DataFrame(data=empty_list)       
with pd.ExcelWriter(r'C:UsersADesktopexcela1.xlsx', mode='A') as writer: 
    df.to_excel(writer, index=False)

But only first column filled with whole elements of the list. I want to do this: After 0th column filled with 6 element, go to next column and again fill it with 6 element. I tried to set a starting column with the help of a count that increases one in each iteration. But that also didn’t work.

df.to_excel(writer, startcol=count, index=False)

How can I handle this? While list is:

[0, 32, -2961, 247, 1, 33, -3757, 196]

Desired excel table like this:

0       1
32      33

(I’m using python 3.8)

Anonymous Asked question May 14, 2021