Write strings/text and pandas dataframe to excel

前端 未结 2 1251
猫巷女王i
猫巷女王i 2020-12-31 19:10

I\'d like to save some text and a dataframe to an excel file like that:

Thus, I\'ve got the following variables:

text1 = \"some text here\"
text2 =          


        
2条回答
  •  没有蜡笔的小新
    2020-12-31 19:26

    Above solution is correct... However

    The write function is part of the xlsxwriter library. When declaring the writer you need to indicate what engine you want pandas to use.

    writer = pd.ExcelWriter("test.xlsx", engine="xlsxwriter")
    

    xlsxwriters functions are then usable through pandas. All other code in the above solution stays the same.

    Ofcourse you require the library to be installed. Here is a programmatic check.

    Would comment but rep to low

提交回复
热议问题