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 is giving the following error:
TypeError: counting() takes exactly 2 arguments (1 given)
I have seen the following thread python pandas: apply a function with arguments to a series. Update and I do not want to use functool.partial as I do not want to import additional classes to be able to pass parameters.
def counting(dic, strWord):
if strWord in dic:
return dic[strWord]
else:
return 0
DF['new_column'] = DF['dic_column'].apply(counting, 'word')
If I give a single parameter, it works:
def awesome_count(dic):
if strWord in dic:
return dic[strWord]
else:
return 0
DF['new_column'] = DF['dic_column'].apply(counting)