W3cubDocs

/pandas 0.25

pandas.CategoricalDtype

class pandas.CategoricalDtype(categories=None, ordered: Union[None, bool, object] = <object object>) [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

Categorical

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

categories An Index containing the unique categories allowed.
ordered Whether the categories have an ordered relationship.

Methods

None

© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.CategoricalDtype.html