【发布时间】:2016-03-29 05:08:23
【问题描述】:
运行代码时出现错误。在查看堆栈溢出中其他问题的类似错误代码后,我通过在 correct_code=list[] 之后使用方括号进行了代码更改,但仍然出现错误。有趣的是,这段代码在周五运行完美,而我整个周末都没有碰它。
我正在使用几个 csv 进行 QAQC,每个 csv 都包含一个字母数字物种代码列表。
Original code:
#create an array for the flagged codes to be placed
species_not_in_state = []
#make a list of the species which are found in the state
correct_code=list(set(fire_species_code).intersection(set(state_species_code)))
#for codes which are not found in that state make a second list
for item in fire_species_code:
if item not in correct_code:
species_not_in_state.append(item)
print(species_not_in_state)
TypeError Traceback(最近一次调用最后一次) 在 () 3 4 #列出在该州发现的物种 ----> 5 correct_code=list[set(fire_species_code).intersection(set(state_species_code))] 6 7
TypeError: 'enumerate' 对象不可调用
Dataset headers:
Fire_species_code:
0 AGFR
1 AGFR
2 AGFR
3 AGFR
4 AGFR
Name: Species, dtype: object
State_species_code
0 ACARO2
1 ACSC5
2 ACSC5
3 ACSC5
4 ACSC5
Name: Symbol, dtype: object
【问题讨论】:
-
在您的代码列表中称为函数列表()。但是在错误信息中列表被用作列表[...] 所以再次检查你的代码。
-
无论如何我都会得到同样的错误:------------------------ ---------------------------------------- TypeError Traceback (最近一次调用最后一次)
in () 3 4 #列出该州的物种列表----> 5 correct_code=list(set(fire_species_code).intersection(set(state_species_code)) ) 6 7 TypeError: 'enumerate' 对象不可调用 -
显示数据 fire_species_code 和 state_species_code 的样子。
-
我添加了来自 fire_species_code 和 state-species_code 的标题。不确定这是否是最好的方法,我是 stackoverflow 的新手。
-
试试 set(fire_species_code) & set(state_species_code)
标签: python-3.x enumerate