Index based on an underlying :class:`Categorical`. CategoricalIndex, like Categorical, can only take on a limited, and usually fixed, number of possible values (`categories`). Also, like Categorical, it might have an order, but numerical operations (additions, divisions, ...) a
| 76 | ) |
| 77 | @set_module("pandas") |
| 78 | class CategoricalIndex(NDArrayBackedExtensionIndex): |
| 79 | """ |
| 80 | Index based on an underlying :class:`Categorical`. |
| 81 | |
| 82 | CategoricalIndex, like Categorical, can only take on a limited, |
| 83 | and usually fixed, number of possible values (`categories`). Also, |
| 84 | like Categorical, it might have an order, but numerical operations |
| 85 | (additions, divisions, ...) are not possible. |
| 86 | |
| 87 | Parameters |
| 88 | ---------- |
| 89 | data : array-like (1-dimensional) |
| 90 | The values of the categorical. If `categories` are given, values not in |
| 91 | `categories` will be replaced with NaN. |
| 92 | categories : index-like, optional |
| 93 | The categories for the categorical. Items need to be unique. |
| 94 | If the categories are not given here (and also not in `dtype`), they |
| 95 | will be inferred from the `data`. |
| 96 | ordered : bool, optional |
| 97 | Whether or not this categorical is treated as an ordered |
| 98 | categorical. If not given here or in `dtype`, the resulting |
| 99 | categorical will be unordered. |
| 100 | dtype : CategoricalDtype or "category", optional |
| 101 | If :class:`CategoricalDtype`, cannot be used together with |
| 102 | `categories` or `ordered`. |
| 103 | copy : bool, default False |
| 104 | Make a copy of input ndarray. |
| 105 | name : object, optional |
| 106 | Name to be stored in the index. |
| 107 | |
| 108 | Attributes |
| 109 | ---------- |
| 110 | codes |
| 111 | categories |
| 112 | ordered |
| 113 | |
| 114 | Methods |
| 115 | ------- |
| 116 | rename_categories |
| 117 | reorder_categories |
| 118 | add_categories |
| 119 | remove_categories |
| 120 | remove_unused_categories |
| 121 | set_categories |
| 122 | as_ordered |
| 123 | as_unordered |
| 124 | map |
| 125 | |
| 126 | Raises |
| 127 | ------ |
| 128 | ValueError |
| 129 | If the categories do not validate. |
| 130 | TypeError |
| 131 | If an explicit ``ordered=True`` is given but no `categories` and the |
| 132 | `values` are not sortable. |
| 133 | |
| 134 | See Also |
| 135 | -------- |
no outgoing calls