pandas.factorize
pandas 3.1.1 · General functions · function
Encode distinct values as integers and return the codes alongside the corresponding unique values.
Call syntax
pd.factorize(values, sort=False, use_na_sentinel=True, size_hint=None)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
values |
Required Positional or keyword |
sequence Supply values to transform, match, aggregate, or use as data. |
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 |
size_hint |
Optional Positional or keyword Default None |
int |
Returns
codes · ndarray; uniques · ndarray, Index, or Categorical