1
functools.partial
を使用している問題が発生しました。Python: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です。
エラー:私はpartial
機能を使用しています
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
私はapply
機能を使用したいので、次のとおりです。あなたはあなたのpartial()
オブジェクトを与えた
products['word_count'].apply(functools.partial(awsome_count,0)
ねえ、答えは間違いなく役に立ちました。私はちょうど今投票しました、私が間違って投票したかどうかは分かりません。申し訳ありません。 – alan
125ポイント以上になるまでダウンボートできないので、心配する必要はありません。 :-) –