pandas.Index.is_categorical — pandas 2.2.3 documentation (original) (raw)
final Index.is_categorical()[source]#
Check if the Index holds categorical data.
Deprecated since version 2.0.0: Use isinstance(index.dtype, pd.CategoricalDtype) instead.
Returns:
bool
True if the Index is categorical.
See also
Index for categorical data.
Check if the Index only consists of booleans (deprecated).
Check if the Index only consists of integers (deprecated).
Check if the Index is a floating type (deprecated).
Check if the Index only consists of numeric data (deprecated).
Check if the Index is of the object dtype. (deprecated).
Check if the Index holds Interval objects (deprecated).
Examples
idx = pd.Index(["Watermelon", "Orange", "Apple", ... "Watermelon"]).astype("category") idx.is_categorical()
True
idx = pd.Index([1, 3, 5, 7]) idx.is_categorical()
False
s = pd.Series(["Peter", "Victor", "Elisabeth", "Mar"]) s 0 Peter 1 Victor 2 Elisabeth 3 Mar dtype: object s.index.is_categorical()
False