pandas.CategoricalDtype¶
-
class
pandas.
CategoricalDtype
(categories=None, ordered: Optional[bool] = False)[source]¶ Type for categorical data with the categories and orderedness.
Changed in version 0.21.0.
- Parameters
- categoriessequence, optional
Must be unique, and must not contain any nulls.
- orderedbool or None, default False
Whether or not this categorical is treated as a ordered categorical. None can be used to maintain the ordered value of existing categoricals when used in operations that combine categoricals, e.g. astype, and will resolve to False if there is no existing ordered to maintain.
See also
Notes
This class is useful for specifying the type of a
Categorical
independent of the values. See CategoricalDtype for more.Examples
>>> t = pd.CategoricalDtype(categories=['b', 'a'], ordered=True) >>> pd.Series(['a', 'b', 'a', 'c'], dtype=t) 0 a 1 b 2 a 3 NaN dtype: category Categories (2, object): [b < a]
Attributes
An
Index
containing the unique categories allowed.Whether the categories have an ordered relationship.
Methods
None