I want to apply a single function to a dataframe column. This function returns multiple results which I want to go to multiple columns in the original dataframe. I cant seem to get around the "too many values to unpack" error....
df = pd.DataFrame(data={'x': [1,2,3,4]})
x
0 1
1 2
2 3
3 4
The function I want to apply :
def do_math(x):
double = 2*x
triple = 3*x
return double, triple
My attempt to apply it (which doesnt work):
df['DOUBLE'], df['TRIPLE'] = df['x'].apply(do_math)
What I want :
x DOUBLE TRIPLE
0 1 2 3
1 2 4 6
2 3 6 9
3 4 8 12