pandas.factorize(values, sort=False, order=None, na_sentinel=-1, size_hint=None)[source]

Encode input values as an enumerated type or categorical variable


values : Sequence

ndarrays must be 1-D. Sequences that aren’t pandas objects are coereced to ndarrays before factorization.

sort : boolean, default False

Sort by values

na_sentinel : int, default -1

Value to mark “not found”

size_hint : hint to the hashtable sizer


labels : the indexer to the original array

uniques : ndarray (1-d) or Index

the unique values. Index is returned when passed values is Index or Series

note: an array of Periods will ignore sort as it returns an always sorted


Scroll To Top