xxxxxxxxxx
# importing libraries
import numpy as np
import pandas as pd
from pandas.api.types import CategoricalDtype
labels, uniques = pd.factorize(['b', 'd', 'd', 'c', 'a', 'c', 'a', 'b'])
print(labels)
# [0 1 1 2 3 2 3 0]
print(uniques)
# ['b' 'd' 'c' 'a']