猿问

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

我遇到了这个错误:


AttributeError: 'Workbook' object has no attribute 'add_chart'

运行此代码时(python 版本 3.7.4):


import re

import pandas as pd

from pandas import ExcelWriter

from pandas import ExcelFile

import 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.book


chart = 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.

        """

我错过了什么?


哆啦的时光机
浏览 684回答 1
1回答

MM们

添加这一行import xlsxwriter正如本 Q/A中所建议的那样,并按照评论中的建议进行指定xlsxwriter,解决了这个问题。
随时随地看视频慕课网APP

相关分类

Python
我要回答