TypeError: to_excel () got multiple values for argument 'sheet_name'
I am trying to store different data across different sheets like this:
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 getting the following error:
TypeError: to_excel() got multiple values for argument 'sheet_name'
How can I solve this?
+3
source to share
2 answers
I tested several sampled data and it worked as expected:
import pandas as pd
from io import BytesIO
bio = BytesIO()
df1 = pd.DataFrame({'Data': [11, 12, 13, 14]})
df2 = pd.DataFrame({'Data': [21, 22, 23, 24]})
with pd.ExcelWriter(bio, engine='xlsxwriter') as writer:
df1.to_excel(writer, sheet_name='Summary')
df2.to_excel(writer, sheet_name='HistoricalISIN')
with open('pandas_file.xlsx', 'wb') as w:
w.write(bio.getvalue())
Output:
Versions:
Python: Python 2.7.13 :: Anaconda 4.3.1 (64-bit)
xlsxwriter: 0.9.6
pandas: 0.19.2
+2
source to share