How to pass multiple arguments to the apply function

后端 未结 2 2051
囚心锁ツ
囚心锁ツ 2021-02-08 07:09

I have a method called counting that takes 2 arguments. I need to call this method using the apply() method. However when I am passing the two parameters to the apply method it

2条回答
  •  不思量自难忘°
    2021-02-08 07:52

    The accepted answer is totally perfect. Taught me some interesting things about Python. But just for fun, here's more precisely what we're looking for:

    selected_words =  ['awesome', 'great', 'fantastic', 'amazing', 'love', 'horrible', 'bad', 'terrible', 'awful', 'wow', 'hate']
    for this_word in selected_words:
        products[this_word] = products['word_count'].apply(lambda dic: dic.get(this_word, 0))
    

    Thanks for posting the question!

提交回复
热议问题