import pandas as pd
Let\'s say I have a dataframe
like so:
df = pd.DataFrame({\"a\":range(4),\"b\":range(1,5)})
the following solution to this frustratingly frustrating question works for me. I found the original suggestion in another StackOverflow post a while ago. The trick is to wrap up the return values into a Series like this:
def divideAndMultiply(x,y):
return pd.Series([x/y, x*y])
Then this works as you wanted:
df[['e','f']] = df.apply( lambda x: divideAndMultiply(x["a"],2) , axis =1)