I can pass a StringIO object to pd.to_csv() just fine:
io = StringIO.StringIO()
pd.DataFrame().to_csv(io)
But when using the excel writer,
For those not using xlsxwriter
as their engine=
for to_excel
here is a solution to use openpyxl
in memory:
in_memory_file = StringIO.StringIO()
xlw = pd.ExcelWriter('temp.xlsx', engine='openpyxl')
# ... do many .to_excel() thingies
xlw.book.save(in_memory_file)
# if you want to read it or stream to a client, don't forget this
in_memory_file.seek(0)
explanation: the ExcelWriter
wrapper class exposes the engines individual workbook through the .book
property. For openpyxl
you can then use the Workbook.save
method as usual!