pandas 1.4.2

AttributesMethodsNotesParametersRaisesBackRef

Attributes

codes :
categories :
ordered :

CategoricalIndex, like Categorical, can only take on a limited, and usually fixed, number of possible values (:None:None:`categories`). Also, like Categorical, it might have an order, but numerical operations (additions, divisions, ...) are not possible.

Methods

Notes

See the :None:None:`user guide <https://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html#categoricalindex>` for more.

Parameters

data : array-like (1-dimensional)

The values of the categorical. If :None:None:`categories` are given, values not in :None:None:`categories` will be replaced with NaN.

categories : index-like, optional

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 :None:None:`data`.

ordered : bool, optional

Whether or not this categorical is treated as an ordered categorical. If not given here or in dtype , the resulting categorical will be unordered.

dtype : CategoricalDtype or "category", optional

If CategoricalDtype , cannot be used together with :None:None:`categories` or :None:None:`ordered`.

copy : bool, default False

Make a copy of input ndarray.

name : object, optional

Name to be stored in the index.

Raises

ValueError

If the categories do not validate.

TypeError

If an explicit ordered=True is given but no :None:None:`categories` and the :None:None:`values` are not sortable.

Index based on an underlying Categorical .

See Also

Categorical

A categorical array.

CategoricalDtype

Type for categorical data.

Index

The base pandas Index type.

Examples

This example is valid syntax, but we were not able to check execution
>>> 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 :

This example is valid syntax, but we were not able to check execution
>>> 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.

This example is valid syntax, but we were not able to check execution
>>> 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')
This example is valid syntax, but we were not able to check execution
>>> ci.min()
'c'
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.arrays.categorical.Categorical pandas.core.dtypes.concat.union_categoricals pandas.core.indexes.base.Index.is_categorical pandas.core.indexes.base.Index

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/indexes/category.py#57
type: <class 'type'>
Commit: