I am getting the following error when trying to call(by value) a function named make_dashboard

Function call:

make_dashboard(x=1948, gdp_change=10, unemployment=3.75, title=title, file_name=file_name)
*Error:* AttributeError                            Traceback (most recent call last)
<ipython-input-42-8f2b4601acb0> in <module>()
      1 # Fill up the parameters in the following function:
----> 2 make_dashboard(1948, 10, 3.75, title, file_name)
      3 #make_dashboard(1948, 10, unemployment=3.75, title=title, file_name=file_name)

<ipython-input-5-0d2e581d2fa5> 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'

*Function:* 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)

The attributes 'x','gdp_change' and 'unemployment' used in the function are dataframes. Kindly someone help me with this error.

Tried entering values for attributes while calling the function make_dashboard(x=1948, gdp_change=10, unemployment=3.75, title=title, file_name=file_name)

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=1948, gdp_change=10, unemployment=3.75, title=title, file_name=file_name)

expected is the dashboard displayed based on attributes

Actual: Error : 
 AttributeError                            Traceback (most recent call last)
<ipython-input-42-8f2b4601acb0> in <module>()
      1 # Fill up the parameters in the following function:
----> 2 make_dashboard(1948, 10, 3.75, title, file_name)
      3 #make_dashboard(1948, 10, unemployment=3.75, title=title, file_name=file_name)

<ipython-input-5-0d2e581d2fa5> 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 Answers

0
Community On

Manipulate the code below:

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)