So, I have a function like below:
def do_something(row, args):
# doing something
return arr
where arr = array([1, 2, 3, 4, 5])
and in my main function, I have a pandas DataFrame object df, it has columns A, B, C, D, E along with other columns.
I use function do_something as below, try to assign each of the elements of the returning array to the columns:
df[['A', 'B', 'C', 'D', 'E']] = df.apply(lambda row: do_something(row, args), axis=1)
However, it gave me an error:
ValueError: Must have equal len keys and values when setting with an iterable
I think it means I'm trying to assign the whole array as one variable to multiple columns in my df, hence the unequal length trigger the error. But I'm not sure how to make my goal.
df?