属性错误:“ int”对象没有属性

时间:2019-09-29 14:42:42

标签: python

def make_dashboard(x, gdp_change, unemployment, title, file_name):
    output_file(file_name)
    p = figure(title=title, x_axis_label='year', y_axis_label='%')
    p.line(x.squeeze(), gdp_change.squeeze(), color="firebrick", line_width=4, legend="% GDP change")
    p.line(x.squeeze(), unemployment.squeeze(), line_width=4, legend="% unemployed")
    show(p)

make_dashboard(x=1952, gdp_change=6.0, unemployment=3.025000, title='dashboard', file_name='index.html')

我收到此错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-60-b89657d5e9d6> in <module>
      1 # Fill up the parameters in the following function:
----> 2 make_dashboard(x=1952, gdp_change=6.0, unemployment=3.025000, title='dashboard', file_name='index.html')

<ipython-input-55-93fed9a96764> in make_dashboard(x, gdp_change, unemployment, title, file_name)
      2     output_file(file_name)
      3     p = figure(title=title, x_axis_label='year', y_axis_label='%')
----> 4     p.line(x.squeeze(), gdp_change.squeeze(), color="firebrick", line_width=4, legend="% GDP change")
      5     p.line(x.squeeze(), unemployment.squeeze(), line_width=4, legend="% unemployed")
      6     show(p)

AttributeError: 'int' object has no attribute 'squeeze'

1 个答案:

答案 0 :(得分:0)

您正在按原始类型调用方法,例如int和float。当您传递x = 1952时,python会将x解释为一个int,这不是一个对象。您可以尝试squeeze(x)和squeeze(gdb_change)