-1

'''

perstate = df[df['State'] != '']['State'].value_counts().to_dict()
data = [dict(
        type = 'choropleth',
        autocolorscale = False,
        colorscale = 'Blues',
        reversescale = True,
        locations = list(perstate.keys()),
        locationmode = 'USA-states',
        text = list(perstate.values()),
        z = list(perstate.values()),
        marker = dict(
            line = dict(
                color = 'rgb(255, 255, 255)',
                width = 2)
            ),
        )]

layout = dict(
         title = 'Bachelor contestants by State',
         geo = dict(
             scope = 'usa',
             projection = dict(type = 'albers usa'),
             countrycolor = 'rgb(255, 255, 255)',
             showlakes = True,
             lakecolor = 'rgb(255, 255, 255)')
         )

figure = dict(data = data, layout = layout)
iplot(figure)

'''

This is giving me the following: TypeError
Traceback (most recent call last)

<ipython-input-294-8cdc028c4fa9> in <module>
      7         colorscale = 'Blues',
      8         reversescale = True,
----> 9         locations = list(perstate.keys()),
     10         locationmode = 'USA-states',
     11         text = list(perstate.values()),

TypeError: 'list' object is not callable

It was working earlier today and I haven't changed anything. Why could this be happening? I am using a notebook in Kaggle. I am trying to take the column 'State' which has the states abbreviations and I want to make a heat map.

Elit Dogu
  • 1
  • 1
  • Could you give the whole error, including the line number, as it is currently unproducible due to the nature of this problem. Most likely, you have a list e.g. a list named xyz and you are doing xyz(), which is not possible as the list is not a function. Perhaps you have variable names overlapping with function names. – RealPawPaw Nov 17 '19 at 06:34
  • @RealPawPaw Just edited so it shows the whole error! Thank you – Elit Dogu Nov 17 '19 at 06:43
  • 1
    Do you have a variable named called 'list'? – RealPawPaw Nov 17 '19 at 06:43
  • @RealPawPaw I do not, I thought that would be necessary for the heatmap – Elit Dogu Nov 17 '19 at 06:47
  • @ElitDogu Is the solution by RealPawPaw correct? – AMC Nov 17 '19 at 07:03

1 Answers1

2

Based on the error, it is most likely that you have redefined the name list to a variable name, so that when you call list() to cast a variable to a type of list, the Python interpreter is actually trying to call your redefined variable as a function.

Example:

print(list("123")) # prints ["1", "2", "3"]

Now, if you define a variable called list, this happens:

list = ["redefining", "list"]
print(list("123")) # TypeError: 'list' object is not callable

Python thinks you've tried to call a variable as a function!

To resolve this issue, simply rename list to another name. The full code hasn't been posted, but you've likely redefined list at least somewhere.

RealPawPaw
  • 988
  • 5
  • 9