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, I am having a lot more trouble.
io = StringIO.StringIO()
writer = pd.ExcelWriter(io)
pd.DataFrame().to_excel(writer,"sheet name")
writer.save()
Returns an
AttributeError: StringIO instance has no attribute 'rfind'
I'm trying to create an ExcelWriter
object without calling pd.ExcelWriter()
but am having some trouble. This is what I've tried so far:
from xlsxwriter.workbook import Workbook
writer = Workbook(io)
pd.DataFrame().to_excel(writer,"sheet name")
writer.save()
But now I am getting an AttributeError: 'Workbook' object has no attribute 'write_cells'
How can I save a pandas dataframe in excel format to a StringIO
object?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…