how to convert string labels to numpy array code example
Example 1: how to convert string labels to numpy array
print (pd.factorize(L)[0])
[0 1 2 1 0]
Example 2: how to convert string labels to numpy array
L = ['ABC', 'DEF', 'GHI', 'DEF', 'ABC']
print (np.unique(L, return_inverse=True)[1])
[0 1 2 1 0]