为了账号安全,请及时绑定邮箱和手机立即绑定

“工作簿”对象没有属性“add_chart”

“工作簿”对象没有属性“add_chart”

哆啦的时光机 2022-07-05 17:42:04
我遇到了这个错误:AttributeError: 'Workbook' object has no attribute 'add_chart'运行此代码时(python 版本 3.7.4):import reimport pandas as pdfrom pandas import ExcelWriterfrom pandas import ExcelFileimport numpy# ... other code here not involved to this part ...df = pd.DataFrame({"city": city_list, "tourist": tourist_list, "month": month_list})writer = pd.ExcelWriter('C:\\Users\\portovenere\\Downloads\\exc.xlsx')workbook = writer.bookchart = workbook.add_chart({'type': 'column'})chart.add_series({    'totals':     '=Sheet1!$A$3:$A$21',    'gap':        2,})add_chart我正在关注的这个pandas xlsx-writer 文档中解释了用法。我看到add_chart在XlsxWriter/workbook.py第 228 行定义def add_chart(self, options):        """        Create a chart object.        Args:            options: The chart type and subtype options.        Returns:            Reference to a Chart object.        """我错过了什么?
查看完整描述

1 回答

?
MM们

TA贡献1886条经验 获得超2个赞

添加这一行

import xlsxwriter

正如本 Q/A中所建议的那样,并按照评论中的建议进行指定xlsxwriter,解决了这个问题。


查看完整回答
反对 回复 2022-07-05
  • 1 回答
  • 0 关注
  • 683 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号