Skip to content

Commit c986386

Browse files
topper-123WillAyd
authored andcommitted
DOC: CategoricalIndex doc string (pandas-dev#24852)
1 parent 1490d0c commit c986386

File tree

1 file changed

+63
-12
lines changed

1 file changed

+63
-12
lines changed

pandas/core/indexes/category.py

+63-12
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,35 @@
4242
typ='method', overwrite=True)
4343
class CategoricalIndex(Index, accessor.PandasDelegate):
4444
"""
45-
Immutable Index implementing an ordered, sliceable set. CategoricalIndex
46-
represents a sparsely populated Index with an underlying Categorical.
45+
Index based on an underlying :class:`Categorical`.
46+
47+
CategoricalIndex, like Categorical, can only take on a limited,
48+
and usually fixed, number of possible values (`categories`). Also,
49+
like Categorical, it might have an order, but numerical operations
50+
(additions, divisions, ...) are not possible.
4751
4852
Parameters
4953
----------
50-
data : array-like or Categorical, (1-dimensional)
51-
categories : optional, array-like
52-
categories for the CategoricalIndex
53-
ordered : boolean,
54-
designating if the categories are ordered
55-
copy : bool
56-
Make a copy of input ndarray
57-
name : object
58-
Name to be stored in the index
54+
data : array-like (1-dimensional)
55+
The values of the categorical. If `categories` are given, values not in
56+
`categories` will be replaced with NaN.
57+
categories : index-like, optional
58+
The categories for the categorical. Items need to be unique.
59+
If the categories are not given here (and also not in `dtype`), they
60+
will be inferred from the `data`.
61+
ordered : bool, optional
62+
Whether or not this categorical is treated as an ordered
63+
categorical. If not given here or in `dtype`, the resulting
64+
categorical will be unordered.
65+
dtype : CategoricalDtype or the string "category", optional
66+
If :class:`CategoricalDtype`, cannot be used together with
67+
`categories` or `ordered`.
68+
69+
.. versionadded:: 0.21.0
70+
copy : bool, default False
71+
Make a copy of input ndarray.
72+
name : object, optional
73+
Name to be stored in the index.
5974
6075
Attributes
6176
----------
@@ -75,9 +90,45 @@ class CategoricalIndex(Index, accessor.PandasDelegate):
7590
as_unordered
7691
map
7792
93+
Raises
94+
------
95+
ValueError
96+
If the categories do not validate.
97+
TypeError
98+
If an explicit ``ordered=True`` is given but no `categories` and the
99+
`values` are not sortable.
100+
78101
See Also
79102
--------
80-
Categorical, Index
103+
Index : The base pandas Index type.
104+
Categorical : A categorical array.
105+
CategoricalDtype : Type for categorical data.
106+
107+
Notes
108+
-----
109+
See the `user guide
110+
<http://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html#categoricalindex>`_
111+
for more.
112+
113+
Examples
114+
--------
115+
>>> pd.CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'])
116+
CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'], categories=['a', 'b', 'c'], ordered=False, dtype='category') # noqa
117+
118+
``CategoricalIndex`` can also be instantiated from a ``Categorical``:
119+
120+
>>> c = pd.Categorical(['a', 'b', 'c', 'a', 'b', 'c'])
121+
>>> pd.CategoricalIndex(c)
122+
CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'], categories=['a', 'b', 'c'], ordered=False, dtype='category') # noqa
123+
124+
Ordered ``CategoricalIndex`` can have a min and max value.
125+
126+
>>> ci = pd.CategoricalIndex(['a','b','c','a','b','c'], ordered=True,
127+
... categories=['c', 'b', 'a'])
128+
>>> ci
129+
CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'], categories=['c', 'b', 'a'], ordered=True, dtype='category') # noqa
130+
>>> ci.min()
131+
'c'
81132
"""
82133

83134
_typ = 'categoricalindex'

0 commit comments

Comments
 (0)