pandas.api.types.CategoricalDtype¶
-
class
pandas.api.types.CategoricalDtype(categories=None, ordered=None)[source]¶ Type for categorical data with the categories and orderedness
Changed in version 0.21.0.
Parameters: categories : sequence, optional
Must be unique, and must not contain any nulls.
- ordered : bool, default False
See also
Notes
This class is useful for specifying the type of a
Categoricalindependent of the values. See CategoricalDtype for more.Examples
>>> t = 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
categoriesAn Indexcontaining the unique categories allowed.orderedWhether the categories have an ordered relationship Methods
None