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
+ 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.
47
53
48
54
Parameters
49
55
----------
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
56
73
Make a copy of input ndarray
57
- name : object
74
+ name : object, optional
58
75
Name to be stored in the index
59
76
60
77
Attributes
61
78
----------
62
79
codes
63
80
categories
64
81
ordered
82
+ dtype
65
83
66
84
Methods
67
85
-------
@@ -75,9 +93,46 @@ class CategoricalIndex(Index, accessor.PandasDelegate):
75
93
as_unordered
76
94
map
77
95
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
+
78
110
See Also
79
111
--------
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'
81
136
"""
82
137
83
138
_typ = 'categoricalindex'
0 commit comments