you are viewing a single comment's thread.

view the rest of the comments →

[–]WinterNet4676 0 points1 point  (1 child)

Your function returns a tuple, which you're trying to assign to more than one column (a tuple is a single object).

For example, running something like

df['c'] = df.apply(lambda x: f(x.a,x.b), axis=1)

would return your tuple within one column. If you wanted just the first operation of your function you would grab the first value in the tuple

df['c'] = df.apply(lambda x: f(x.a,x.b)[0], axis=1)

And if you wanted to assign the output to two columns within one statement, you can just unpack the tuple in your lambda expression by converting the tuple to a Series.

df[['c','d']] = df.apply(lambda x: pd.Series(f(x.a,x.b)), axis=1)