42
42
typ = 'method' , overwrite = True )
43
43
class CategoricalIndex (Index , accessor .PandasDelegate ):
44
44
"""
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.
47
51
48
52
Parameters
49
53
----------
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.
59
74
60
75
Attributes
61
76
----------
@@ -75,9 +90,45 @@ class CategoricalIndex(Index, accessor.PandasDelegate):
75
90
as_unordered
76
91
map
77
92
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
+
78
101
See Also
79
102
--------
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'
81
132
"""
82
133
83
134
_typ = 'categoricalindex'
0 commit comments