ExtensionArray.
factorize
Encode the extension array as an enumerated type.
Value to use in the codes array to indicate missing values.
An integer NumPy array that’s an indexer into the original ExtensionArray.
An ExtensionArray containing the unique values of self.
Note
uniques will not contain an entry for the NA value of the ExtensionArray if there are any missing values present in self.
See also
Top-level factorize method that dispatches here.
Notes
pandas.factorize() offers a sort keyword as well.
pandas.factorize()