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 |
|---|---|---|
|
||
|
||
|
||
|
||
|
||
|
||
|
Construction#
Method |
Description |
Example |
|---|---|---|
|
Statistics#
Method |
Description |
Example |
|---|---|---|
|
||
|
||
|
Comparison#
Method |
Description |
Example |
|---|---|---|
|
||
|
||
|
||
|
||
|
||
|
||
|
I/O#
Method |
Description |
Example |
|---|---|---|
|
Conversion#
Method |
Description |
Example |
|---|---|---|
|
Iteration#
Method |
Description |
Example |
|---|---|---|
|
Set Operations#
Method |
Description |
Example |
|---|---|---|
|
Categorical Methods#
Method |
Description |
Example |
|---|---|---|
|
||
|
||
|
||
|
||
|
||
|
||
|
Other Methods#
Method |
Description |
Example |
|---|---|---|
|
||
|
||
|
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