Skip to content

Commit

Permalink
[DOC]: Documentation updated for codes
Browse files Browse the repository at this point in the history
  • Loading branch information
chethanc1011 committed Dec 7, 2023
1 parent 0d853e7 commit 7230872
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,37 @@ def levshape(self) -> Shape:

@property
def codes(self) -> FrozenList:
"""
Codes in MultiIndex refers to Integer codes for each level of
MultiIndex.
The codes attribute represents the integer codes that are used
internally to represent each label in the corresponding level of the
MultiIndex. These codes facilitate efficient storage and retrieval of
hierarchical data.
Each element in the list corresponds to a level in the MultiIndex,
and the arrays within the list contain the integer codes for the
labels at that level.
Examples
-------
>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
>>> df.set_index(['A', 'B'], inplace=True)
>>> df.index.codes
[array([0, 1, 2]), array([0, 1, 2])]
>>> levels = [[2, 3, 1], ['Gold', 'Silver', 'Bronze']]
>>> codes = [[2, 0, 1], [0, 1, 2]]
>>> index = pd.MultiIndex(levels=levels, codes=codes)
>>> index
MultiIndex([(1, 'Gold'),
(2, 'Silver'),
(3, 'Bronze')],
)
>>> index.codes
FrozenList([[2, 0, 1], [0, 1, 2]])
"""
return self._codes

def _set_codes(
Expand Down

0 comments on commit 7230872

Please sign in to comment.