CategoricalIndex#

class CategoricalIndex#

Index based on an underlying Categorical.

Example#

import pandasCore as pd

# Create CategoricalIndex
idx = pd.CategoricalIndex([1, 2, 3], name='my_index')
print(len(idx))  # 3

Attributes#

Attribute

Description

Example

categories

codes

dtype

empty

name

ordered

size

Construction#

Method

Description

Example

__init__() (data: object = None, categories: object = None, ordered: object = None, dtype: object = None, copy: bool = False, name: object = None)

View

Statistics#

Method

Description

Example

max() ()

min() ()

nunique() ()

Comparison#

Method

Description

Example

__eq__() (value: str)

__ge__() (value: str)

__gt__() (value: str)

__le__() (value: str)

__lt__() (value: str)

__ne__() (value: str)

equals() (other: pandasCore.CategoricalIndex)

I/O#

Method

Description

Example

tolist() ()

Conversion#

Method

Description

Example

copy() ()

Iteration#

Method

Description

Example

__len__() ()

Set Operations#

Method

Description

Example

unique() ()

Categorical Methods#

Method

Description

Example

add_categories() (new_categories: collections.abc.Sequence[str])

as_ordered() ()

as_unordered() ()

remove_categories() (removals: collections.abc.Sequence[str])

rename_categories() (new_categories: object)

reorder_categories() (new_categories: collections.abc.Sequence[str])

set_categories() (new_categories: collections.abc.Sequence[str], rename: bool = False)

Other Methods#

Method

Description

Example

__hash__() ()

__repr__() ()

__str__() ()

Code Examples#

The following examples are extracted from the test suite.

__init__ (test_categoricalindex_comp.py:39)
29ctx = TestContext()
30
31
32# ==================== Test Functions ====================
33
34def test_categoricalindex_construction():
35    """Test CategoricalIndex construction with various parameters"""
36    f_print_header("Test: CategoricalIndex Construction")
37
38    # Basic construction with no arguments
39    pc_idx = pandasCore.CategoricalIndex()
40    ctx.assert_equal(0, len(pc_idx), "CategoricalIndex() - empty")
41
42    # Construction with data
43    try:
44        pc_idx2 = pandasCore.CategoricalIndex(data=['a', 'b', 'c', 'a', 'b'])
45        pd_idx2 = pd.CategoricalIndex(['a', 'b', 'c', 'a', 'b'])
46        ctx.assert_equal(len(pd_idx2), len(pc_idx2), "CategoricalIndex with data - length")
47    except Exception as e:
48        f_print_warning(f"CategoricalIndex data construction not fully supported: {e}")
49        # Test passes if construction works even without data