cudf.CategoricalDtype#
- class cudf.CategoricalDtype(categories=None, ordered: bool = False)#
Type for categorical data with the categories and orderedness.
- Parameters
- categoriessequence, optional
Must be unique, and must not contain any nulls. The categories are stored in an Index, and if an index is provided the dtype of that index will be used.
- 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.
Examples
>>> import cudf >>> dtype = cudf.CategoricalDtype(categories=['b', 'a'], ordered=True) >>> cudf.Series(['a', 'b', 'a', 'c'], dtype=dtype) 0 a 1 b 2 a 3 <NA> dtype: category Categories (2, object): ['b' < 'a']
Attributes
An
Index
containing the unique categories allowed.Whether the categories have an ordered relationship.
Methods
from_pandas
(dtype)Convert a
pandas.CategrocialDtype
tocudf.CategoricalDtype
Convert a
cudf.CategoricalDtype
topandas.CategoricalDtype
- property categories: GenericIndex#
An
Index
containing the unique categories allowed.Examples
>>> import cudf >>> dtype = cudf.CategoricalDtype(categories=['b', 'a'], ordered=True) >>> dtype.categories StringIndex(['b' 'a'], dtype='object')
- classmethod from_pandas(dtype: CategoricalDtype) CategoricalDtype #
Convert a
pandas.CategrocialDtype
tocudf.CategoricalDtype
Examples
>>> import cudf >>> import pandas as pd >>> pd_dtype = pd.CategoricalDtype(categories=['b', 'a'], ordered=True) >>> pd_dtype CategoricalDtype(categories=['b', 'a'], ordered=True) >>> cudf_dtype = cudf.CategoricalDtype.from_pandas(pd_dtype) >>> cudf_dtype CategoricalDtype(categories=['b', 'a'], ordered=True)
- to_pandas() CategoricalDtype #
Convert a
cudf.CategoricalDtype
topandas.CategoricalDtype
Examples
>>> import cudf >>> dtype = cudf.CategoricalDtype(categories=['b', 'a'], ordered=True) >>> dtype CategoricalDtype(categories=['b', 'a'], ordered=True) >>> dtype.to_pandas() CategoricalDtype(categories=['b', 'a'], ordered=True)