''
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)
''
这给了我以下信息:
类型错误
回溯(最近一次呼叫)
<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
今天早些时候还有用,我什么都没变。为什么会这样?我用的是卡格尔的笔记本。我试着把‘State’列作为状态的缩写,我想做一个热图
基于此错误,很可能您已经将名称
list
重新定义为变量名,因此当您调用list()
将变量强制转换为list
类型时,Python解释器实际上正在尝试将重新定义的变量作为函数调用示例:
现在,如果定义一个名为
list
的变量,则会发生以下情况:Python认为您试图将变量作为函数调用
要解决此问题,只需将
list
重命名为另一个名称。完整的代码还没有发布,但您可能至少在某个地方重新定义了list
相关问题 更多 >
编程相关推荐