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))
将参数传递为kwargs以apply
:
df['events'] = df['data'].apply(count_ones, total_bits=60, group_size=12)
use lambda:
def do_on_col(x, argument1):
return x+argument1
df[col] = df[col].apply(lambda x: do_on_col(x, argument1))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.