pandas.Series.factorize
pandas 3.1.1 · Series and accessors · method
Encode distinct values as integers and return the codes alongside the corresponding unique values.
Call syntax
Series.factorize(sort=False, use_na_sentinel=True)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
sort |
Optional Positional or keyword Default False |
bool Choose whether the resulting labels or groups are sorted where supported. |
use_na_sentinel |
Optional Positional or keyword Default True |
bool |
Returns
codes · ndarray; uniques · ndarray, Index, or Categorical