Say I have a function:
def fn(x)
y = x ** 2
z = x ** 3
return y, z
And I want to use df['x'].apply(lambda x: fn(x))
to return both y
and z
in separate columns. Is there a good way to do this by still using fn(x)
? In reality, my function will be much more complicated - so I only want to run it once within the apply and assign output[0]
, output[1]
, etc to individual columns.