我在使用functools.partial
.
我的代码:
selected_words = ['awesome', 'great', 'fantastic', 'amazing', 'love', 'horrible', 'bad', 'terrible', 'awful', 'wow', 'hate']
def awsome_count(x,i):
if selected_words[i] in x:
y=1
else:
y=0
return y
partialfun=functools.partial(awsome_count,0)
partialfun(products[2]['word_count'])
products
是一个 SFrame。
错误:
TypeError Traceback (most recent call last)
<ipython-input-108-e51348a5d1f0> in <module>()
----> 1 partialfun(products[2]['word_count'])
<ipython-input-66-9ba8c7128add> in awsome_count(x, i)
1 def awsome_count(x,i):
----> 2 if selected_words[i] in x:
3 y=1
4 else:
5 y=0
TypeError: list indices must be integers, not dict
我正在使用partial
函数,是因为我想使用apply
函数:
products['word_count'].apply(functools.partial(awsome_count,0)