I've checked out map, apply, mapapply, and combine, but can't seem to find a simple way of doing the following:
I have a dataframe with 10 columns. I need to pass three of them into a function that takes scalars and returns a scalar ...
some_func(int a, int b, int c) returns int d
I want to apply this and create a new column in the dataframe with the result.
df['d'] = some_func(a = df['a'], b = df['b'], c = df['c'])
All the solutions that I've found seem to suggest to rewrite some_func to work with Series instead of scalars, but this is not possible as it is part of another package. How do I elegantly do the above?
def func(row): return row['a'] * row['b'] * row['c'] df.apply( lambda row: func(row), axis = 1)ideally you want to write your function in a way so that it can operate on the entire series so it's vectorised, can you show what you are really trying to doSeriesas params then you could rewrite it todef some_func(a,b,c): return a*b*c df['d'] = some_func(df['a'], df['b'], df['c'])