Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas apply function with arguments

Tags:

python

pandas

I have one function that takes three arguments. And here's the heading.

def count_ones(num, total_bits, group_size):

And I am trying to apply this function to data column. But it is not returning what I expected. Could anyone help me out on this problem? total_bits are 60 and group_size is 12.

df['events'] = df['data'].apply(count_ones, args =(60, 12))
like image 458
ejshin1 Avatar asked Aug 04 '17 18:08

ejshin1


1 Answers

Pass the arguments as kwargs to apply:

df['events'] = df['data'].apply(count_ones, total_bits=60, group_size=12)
like image 151
harryscholes Avatar answered Sep 23 '22 00:09

harryscholes