pandas.api.types.is_categorical_dtype#

pandas.api.types.is_categorical_dtype(arr_or_dtype)[源代码]#

检查类数组或 dtype 是否为 Categorical dtype。

自 2.2.0 版本弃用: 请改用 isinstance(dtype, pd.CategoricalDtype)。

Parameters:
arr_or_dtypearray-like or dtype

要检查的类数组或 dtype。

Returns:
boolean

类数组或 dtype 是否为 Categorical dtype。

Examples

>>> from pandas.api.types import is_categorical_dtype
>>> from pandas import CategoricalDtype
>>> is_categorical_dtype(object)
False
>>> is_categorical_dtype(CategoricalDtype())
True
>>> is_categorical_dtype([1, 2, 3])
False
>>> is_categorical_dtype(pd.Categorical([1, 2, 3]))
True
>>> is_categorical_dtype(pd.CategoricalIndex([1, 2, 3]))
True