制作美国热图?

'''

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,showlakes = True,lakecolor = 'rgb(255,255)')
         )

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

'''

这给了我以下内容:     TypeError
    追溯(最近一次通话结束)

<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

今天早些时候工作了,我什么都没改变。为什么会这样呢?我在Kaggle使用笔记本电脑。我正在尝试获取“州”列,其中包含州的缩写,我想绘制一个热图。

asdsasdsaffff 回答:制作美国热图?

基于该错误,很可能您已将名称list重新定义为变量名,以便在调用list()时将变量转换为类型{{1} },Python解释器实际上正在尝试将重新定义的变量作为函数调用。

示例:

list

现在,如果定义一个名为print(list("123")) # prints ["1","2","3"] 的变量,则会发生这种情况:

list

Python认为您已尝试将变量作为函数调用!

要解决此问题,只需将list = ["redefining","list"] print(list("123")) # TypeError: 'list' object is not callable 重命名为另一个名称。完整的代码尚未发布,但是您可能至少在某处重新定义了list

本文链接:https://www.f2er.com/3087472.html

大家都在问