I have a function that has multiple inputs, and would like to use SFrame.apply
to create a new column. I can't find a way to pass two arguments into SFrame.apply
.
Ideally, it would take the entry in the column as the first argument, and I would pass in a second argument. Intuitively something like...
def f(arg_1,arg_2):
return arg_1 + arg_2
sf['new_col'] = sf.apply(f,arg_2)
The * symbol is used to pass a variable number of arguments to a function. Typically, this syntax is used to avoid the code failing when we don't know how many arguments will be sent to the function.
The lapply () and sapply () functions can be used for performing multiple functions on a list in R. This function is used in order to avoid the usage of loops in R. The difference between both the functions is the sapply () function does the same job as lapply () function but returns a vector.
The mapply() function in R is used to apply a function FUN to a given list or a vector argument passed to it.
The parameter to input() is a prompt string that prints out, prompting the user what they are supposed to type. It looks best to add a space at the end of the prompt string.
suppose the first argument of function f is one of the column.
Say argcolumn1
in sf, then
sf['new_col'] = sf['argcolumn1'].apply(lambda x:f(x,arg_2))
should work
Try this.
sf['new_col'] = sf.apply(lambda x : f(arg_1, arg_2))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With