pandas.
CategoricalIndex
Index based on an underlying Categorical.
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, …) are not possible.
The values of the categorical. If categories are given, values not in categories will be replaced with NaN.
The categories for the categorical. Items need to be unique. If the categories are not given here (and also not in dtype), they will be inferred from the data.
Whether or not this categorical is treated as an ordered categorical. If not given here or in dtype, the resulting categorical will be unordered.
If CategoricalDtype, cannot be used together with categories or ordered.
CategoricalDtype
Make a copy of input ndarray.
Name to be stored in the index.
If the categories do not validate.
If an explicit ordered=True is given but no categories and the values are not sortable.
ordered=True
See also
Index
The base pandas Index type.
A categorical array.
Type for categorical data.
Notes
See the user guide for more.
Examples
>>> pd.CategoricalIndex(["a", "b", "c", "a", "b", "c"]) CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'], categories=['a', 'b', 'c'], ordered=False, dtype='category')
CategoricalIndex can also be instantiated from a Categorical:
>>> c = pd.Categorical(["a", "b", "c", "a", "b", "c"]) >>> pd.CategoricalIndex(c) CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'], categories=['a', 'b', 'c'], ordered=False, dtype='category')
Ordered CategoricalIndex can have a min and max value.
>>> ci = pd.CategoricalIndex( ... ["a", "b", "c", "a", "b", "c"], ordered=True, categories=["c", "b", "a"] ... ) >>> ci CategoricalIndex(['a', 'b', 'c', 'a', 'b', 'c'], categories=['c', 'b', 'a'], ordered=True, dtype='category') >>> ci.min() 'c'
Attributes
codes
The category codes of this categorical.
categories
The categories of this categorical.
ordered
Whether the categories have an ordered relationship.
Methods
rename_categories(self, \*args, \*\*kwargs)
rename_categories
Rename categories.
reorder_categories(self, \*args, \*\*kwargs)
reorder_categories
Reorder categories as specified in new_categories.
add_categories(self, \*args, \*\*kwargs)
add_categories
Add new categories.
remove_categories(self, \*args, \*\*kwargs)
remove_categories
Remove the specified categories.
remove_unused_categories(self, \*args, …)
remove_unused_categories
Remove categories which are not used.
set_categories(self, \*args, \*\*kwargs)
set_categories
Set the categories to the specified new_categories.
as_ordered(self, \*args, \*\*kwargs)
as_ordered
Set the Categorical to be ordered.
as_unordered(self, \*args, \*\*kwargs)
as_unordered
Set the Categorical to be unordered.
map(self, mapper)
map
Map values using input correspondence (a dict, Series, or function).