我想将我的熊猫数据框导出为xls
文件而不是xlsx
。熊猫 - python导出为xls而不是xlsx - ExcelWriter
我使用ExcelWriter。
我做:
xlsxWriter = pd.ExcelWriter(str(outputName + "- Advanced.xls"))
不幸的是,没有什么产出。
我想我必须改变引擎,但我不知道如何?
我想将我的熊猫数据框导出为xls
文件而不是xlsx
。熊猫 - python导出为xls而不是xlsx - ExcelWriter
我使用ExcelWriter。
我做:
xlsxWriter = pd.ExcelWriter(str(outputName + "- Advanced.xls"))
不幸的是,没有什么产出。
我想我必须改变引擎,但我不知道如何?
您可以使用to_excel
并通过扩展.xls
作为文件名:
df.to_excel(file_name_blah.xls)
大熊猫将使用不同的模块来进行写入Excel工作表,请注意,它会要求你有先决条件第三方模块已安装。
如果由于某种原因你需要显式调用pd.ExcelWriter
,方法如下:
outputName = "xxxx"
xlsWriter = pd.ExcelWriter(str(outputName + "- Advanced.xls"), engine = 'xlwt')
# Convert the dataframe to an Excel Writer object.
test.to_excel(xlsWriter, sheet_name='Sheet1')
# Close the Pandas Excel writer and output the Excel file.
xlsWriter.save()
它的关键,不要忘记save()
命令。这是你的问题。
请注意,您也可以直接设置engine
像这样:test.to_excel('test.xls', engine='xlwt')
不会['df.to_excel'](http://pandas.pydata.org/pandas-docs/stable/generated/pandas .DataFrame.to_excel.html)传递扩展名'.xls'工作? – EdChum
确实如此,你应该将其作为回答@EdChum –
@JulienMarrec完成 – EdChum