diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index e82b641db98fd..45b6b08dc41f2 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1195,7 +1195,7 @@ def to_frame(self, index=True): -------- >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() - animal + animal animal Ant Ant Bear Bear @@ -1511,6 +1511,39 @@ def is_object(self): return is_object_dtype(self.dtype) def is_categorical(self): + """ + Check if the Index holds categorical data. + + Returns + ------- + boolean + True if the Index is categorical. + + See Also + -------- + CategoricalIndex : Index for categorical data. + + 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", "Víctor", "Elisabeth", "Mar"]) + >>> s + 0 Peter + 1 Víctor + 2 Elisabeth + 3 Mar + dtype: object + >>> s.index.is_categorical() + False + """ return self.inferred_type in ['categorical'] def is_interval(self):