4242 typ = 'method' , overwrite = True )
4343class 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+ Immutable index implementing an ordered, sliceable set. CategoricalIndex
46+ represents a sparsely populated index with an underlying
47+ :class:`Categorical`.
48+
49+ `CategoricalIndex`, like `Categorical` can only take on a limited,
50+ and usually fixed, number of possible values (`categories`). Also,
51+ like `Categorical`, it might have an order, but numerical operations
52+ (additions, divisions, ...) are not possible.
4753
4854 Parameters
4955 ----------
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+ data : list-like
57+ The values of the categorical. If categories are given, values not in
58+ categories will be replaced with NaN.
59+ categories : index-like, optional
60+ The categories for the categorical. Items need to be unique.
61+ If the categories are not given here, then they must be provided
62+ in `dtype`.
63+ ordered : bool, optional
64+ Whether or not this categorical is treated as an ordered
65+ categorical. If not given here or in `dtype`, the resulting
66+ categorical will be unordered.
67+ dtype : CategoricalDtype or the string "category", optional
68+ If :class:`CategoricalDtype`, cannot be used together with
69+ `categories` or `ordered`.
70+
71+ .. versionadded:: 0.21.0
72+ copy : bool, default False
5673 Make a copy of input ndarray
57- name : object
74+ name : object, optional
5875 Name to be stored in the index
5976
6077 Attributes
6178 ----------
6279 codes
6380 categories
6481 ordered
82+ dtype
6583
6684 Methods
6785 -------
@@ -75,9 +93,46 @@ class CategoricalIndex(Index, accessor.PandasDelegate):
7593 as_unordered
7694 map
7795
96+ Raises
97+ ------
98+ ValueError
99+ If the categories do not validate.
100+ TypeError
101+ If an explicit ``ordered=True`` is given but no `categories` and the
102+ `values` are not sortable.
103+
104+ Notes
105+ -----
106+ See the `user guide
107+ <https://pandas-docs.github.io/pandas-docs-travis/advanced.html#categoricalindex>`_
108+ for more.
109+
78110 See Also
79111 --------
80- Categorical, Index
112+ Index : The base pandas Index type
113+ Categorical : A categorical variable in classic R / S-plus fashion
114+ CategoricalDtype : Type for categorical data
115+
116+ Examples
117+ --------
118+ >>> pd.CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'])
119+ CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'], categories=['a', 'b', 'c'], ordered=False, dtype='category') # noqa
120+
121+ ``CategoricalIndex`` can also be instantiated from a ``Categorical``:
122+
123+ >>> c = pd.Categorical(['a', 'b', 'c', 'a', 'b', 'c'])
124+ >>> pd.CategoricalIndex(c)
125+ CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'], categories=['a', 'b', 'c'], ordered=False, dtype='category') # noqa
126+
127+ Ordered `CategoricalIndex` can be sorted according to the custom order
128+ of the categories and can have a min and max value.
129+
130+ >>> ci = pd.CategoricalIndex(['a','b','c','a','b','c'], ordered=True,
131+ ... categories=['c', 'b', 'a'])
132+ >>> ci
133+ CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'], categories=['c', 'b', 'a'], ordered=True, dtype='category') # noqa
134+ >>> ci.min()
135+ 'c'
81136 """
82137
83138 _typ = 'categoricalindex'
0 commit comments