Home > database >  Python : DataFrame.to_excel should write the table vertically
Python : DataFrame.to_excel should write the table vertically

Time:10-13

I am trying to write 2 Sheets in a new Excel file

    with pd.ExcelWriter(outputDetailsFile) as writer:
        df1.to_excel(writer, sheet_name='FA',index = False)
        df2.to_excel(writer, sheet_name='TA', index = False)

The above code is working fine. There is only 1 row in that in "df1" Therefore, I need the First Sheet "FA" to be written Vertically instead of Horizontally for better readability

At present it is writing like this : enter image description here

It should Write like this :

enter image description here

Please suggest

CodePudding user response:

Try transposing the index and columns using the T accessor:

df1.T.to_excel(writer, sheet_name='FA',index = False)

  • Related