Boris
Boris

Reputation: 2085

Numba - how to return multiple columns ( arrays) - after group by apply

I would like to run groupby and then apply Numba function on top of a pandas. This is the example :

@nb.jit(nopython=True) 
def my_Numba_function(arr1,arr2):    
    arr1[:] =11
    arr2[:] =22

    return arr1,arr2    

and_df= df_input_imputed.groupby(key_cols_list, as_index = True)[['col_1,'col_2']].\
    apply(lambda x: pd.DataFrame(my_Numba_function(arr1 = x['col_1'].values,arr2 = x['col_2'].values)) )

And instead of getting two columns additional to my index, I am getting the results in a lot of columns ( rows became columns).

enter image description here

How can I fix this ?

Thanks, Boris

Upvotes: 1

Views: 265

Answers (0)

Related Questions