I have a function returning a tuple of values, as an example:
def dumb_func(number):
return number+1,number-1
I'd like to apply it to a pandas DataFrame
df=pd.DataFrame({'numbers':[1,2,3,4,5,6,7]})
test=dumb_df['numbers'].apply(dumb_func)
The result is that test
is a pandas series containing tuples.
Is there a way to use the variable test
or to remplace it to assign the results of the function to two distinct columns 'number_plus_one'
and 'number_minus_one'
of the original DataFrame?