JohnAndrews JohnAndrews -4 years ago 354
Python Question

TypeError: to_excel() got multiple values for argument 'sheet_name'

I am trying to save different dataframes to different worksheets as follow:

import pandas as pd
from pandas import ExcelWriter
import xlsxwriter

// code
bio = BytesIO()
with pd.ExcelWriter(bio, engine='xlsxwriter') as writer:
dfStats.to_excel(writer, sheet_name='Summary')
dfStockdata.to_excel(writer, sheet_name='HistoricalISIN')

# create the workbook
writer.save() // tried both with and without this line
bio.seek(0)
workbook = bio.read()
excelFile = workbook


However, I am receiving the following error:

TypeError: to_excel() got multiple values for argument 'sheet_name'


How can I solve this?

Answer Source

You can try using:

writer = pd.ExcelWriter('output//out.xlsx', engine='xlsxwriter')
dfStats.to_excel(writer, sheet_name='Summary')
dfStockdata.to_excel(writer, sheet_name='HistoricalISIN')
writer.save()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download