Traceback (most recent call last):
File "<pyshell#80>", line 1, in <module>
do_work()
File "C:\pythonwork\readthefile080410.py", line 14, in do_work
populate_frequency5(e,data)
File "C:\pythonwork\readthefile080410.py", line 157, in populate_frequency5
data=medications_minimum3(data,[drug.upper()],1)
File "C:\pythonwork\readthefile080410.py", line 120, in medications_minimum3
counter[row[11]]+=1
TypeError: unhashable type: 'list'
Run Code Online (Sandbox Code Playgroud)
我在这一行得到了上述错误:
data=medications_minimum3(data,[drug.upper()],1)
Run Code Online (Sandbox Code Playgroud)
(我也试过没有括号的drug.upper())
以下是此功能的预览:
def medications_minimum3(c,drug_input,sample_cutoff): #return sample cut off for # medications/physician
d=[]
counter=collections.defaultdict(int)
for row in c:
counter[row[11]]+=1
for row in c:
if counter[row[11]]>=sample_cutoff:
d.append(row)
write_file(d,'/pythonwork/medications_minimum3.csv')
return d
Run Code Online (Sandbox Code Playgroud)
有谁知道我在做错了什么?
我知道我调用这个函数的方式肯定是错误的,因为我从不同的位置调用这个函数并且它工作正常:
d=medications_minimum3(c,drug_input,50)
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助!
python ×1