I have a dataframe df1=
HPE FRE UNE
0 S0 S0 S0
1 S1 S1 S1
using the below code("reduce" is a functool function, sta is a list containing the columns of df1):
reduce(lambda x,y:np.add.outer(x,y),sta).reshape(-1)
I reduced my dataframe to numpy array like this:
['S0S0S0' 'S0S0S1' 'S0S1S0' 'S0S1S1' 'S1S0S0' 'S1S0S1' 'S1S1S0' 'S1S1S1']
but I want my output to look like below:
['S0|S0|S0' 'S0|S0|S1' 'S0|S1|S0' 'S0|S1|S1' 'S1|S0|S0' 'S1|S0|S1' 'S1|S1|S0' 'S1|S1|S1']
How can I do?
TypeError: ufunc 'add' did not contain a loop with signature matching types.addonly works it the array is object dtype. Then the arrayadddelegates the task to theaddmethod of each element, which for strings is ajoin. It does not work forstringdtype arrays. It's a feature, not a designed or documented behavior.addto the others?reduce(lambda x,y:np.add.outer(x,y),df.T.values.tolist())