I have a function which returns a list of length 2. I would like to apply this function to one column in my dataframe and assign the result to two columns.
This actually works:
from pandas import *
def twonumbers(x):
return [2*x, 3*x]
df = DataFrame([1,4,11],columns=['v1'])
concat([df,DataFrame(df['v1'].map(twonumbers).tolist(), columns=['v2','v3'])],axis=1)
But I am looking for a simpler way to do the last line above. Something like this:
df['v3'], df['v2'] = df['v1'].map(twonumbers)