python - 类型错误 : to_excel() got multiple values for argument 'sheet_name'

标签 python python-3.x pandas

我正在尝试将不同的数据框保存到不同的工作表中,如下所示:

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

但是,我收到以下错误:

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

我该如何解决这个问题?

最佳答案

您可以尝试使用:

writer = pd.ExcelWriter('output//out.xlsx', engine='xlsxwriter')
dfStats.to_excel(writer, sheet_name='Summary')
dfStockdata.to_excel(writer, sheet_name='HistoricalISIN')
writer.save()

关于python - 类型错误 : to_excel() got multiple values for argument 'sheet_name' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42973684/

相关文章:

pandas - Folium Choropleth + GeoJSON 引发 AttributeError : 'NoneType'

python - 当推文不包含图像时,T​​weepy python 代码在 'media' 实体上返回 KeyError

python - 将标志从 python 脚本传递到另一个脚本

python - tkinter Canvas 图像不显示

python - 对 Pandas 数据帧行进行矩阵运算

python - 从 RangeIndex 到 DatetimeIndex

python - 为一组点生成最近邻距离图

python - 从Python和标点符号列表中删除表情符号和@users,NLP问题,我的表情符号功能不起作用

python - 键值映射

Python 3.6 : New line command '/n' is ignored when writing to a file on AWS Ubuntu