Skip to content

Commit 5888e36

Browse files
mariadelmarbibiloniTomAugspurger
authored andcommitted
DOC: update the pandas.Index.is_categorical docstring (#20167)
* pandas.Index.is_categorical from base.py documented * pandas.Index.is_categorical from base.py documented and some errors solved * pandas.Index.is_categorical from base.py with new examples and extended summary * Added See Also. Removed Extended summary * Added back whitepace * to_frame formatting
1 parent ac3d893 commit 5888e36

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

pandas/core/indexes/base.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ def to_frame(self, index=True):
11951195
--------
11961196
>>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal')
11971197
>>> idx.to_frame()
1198-
animal
1198+
animal
11991199
animal
12001200
Ant Ant
12011201
Bear Bear
@@ -1511,6 +1511,39 @@ def is_object(self):
15111511
return is_object_dtype(self.dtype)
15121512

15131513
def is_categorical(self):
1514+
"""
1515+
Check if the Index holds categorical data.
1516+
1517+
Returns
1518+
-------
1519+
boolean
1520+
True if the Index is categorical.
1521+
1522+
See Also
1523+
--------
1524+
CategoricalIndex : Index for categorical data.
1525+
1526+
Examples
1527+
--------
1528+
>>> idx = pd.Index(["Watermelon", "Orange", "Apple",
1529+
... "Watermelon"]).astype("category")
1530+
>>> idx.is_categorical()
1531+
True
1532+
1533+
>>> idx = pd.Index([1, 3, 5, 7])
1534+
>>> idx.is_categorical()
1535+
False
1536+
1537+
>>> s = pd.Series(["Peter", "Víctor", "Elisabeth", "Mar"])
1538+
>>> s
1539+
0 Peter
1540+
1 Víctor
1541+
2 Elisabeth
1542+
3 Mar
1543+
dtype: object
1544+
>>> s.index.is_categorical()
1545+
False
1546+
"""
15141547
return self.inferred_type in ['categorical']
15151548

15161549
def is_interval(self):

0 commit comments

Comments
 (0)