Skip to content

Commit 44c08d4

Browse files
bkil-syslogngjorisvandenbossche
authored andcommitted
DOC: update the Index.get_level_values docstring (#20210)
1 parent 384c9b3 commit 44c08d4

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

pandas/core/indexes/base.py

+24-9
Original file line numberDiff line numberDiff line change
@@ -3090,26 +3090,41 @@ def set_value(self, arr, key, value):
30903090

30913091
def _get_level_values(self, level):
30923092
"""
3093-
Return an Index of values for requested level, equal to the length
3094-
of the index.
3093+
Return an Index of values for requested level.
3094+
3095+
This is primarily useful to get an individual level of values from a
3096+
MultiIndex, but is provided on Index as well for compatability.
30953097
30963098
Parameters
30973099
----------
30983100
level : int or str
3099-
``level`` is either the integer position of the level in the
3100-
MultiIndex, or the name of the level.
3101+
It is either the integer position or the name of the level.
31013102
31023103
Returns
31033104
-------
31043105
values : Index
3105-
``self``, as there is only one level in the Index.
3106+
Calling object, as there is only one level in the Index.
31063107
31073108
See also
3108-
---------
3109-
pandas.MultiIndex.get_level_values : get values for a level of a
3110-
MultiIndex
3111-
"""
3109+
--------
3110+
MultiIndex.get_level_values : get values for a level of a MultiIndex
3111+
3112+
Notes
3113+
-----
3114+
For Index, level should be 0, since there are no multiple levels.
31123115
3116+
Examples
3117+
--------
3118+
3119+
>>> idx = pd.Index(list('abc'))
3120+
>>> idx
3121+
Index(['a', 'b', 'c'], dtype='object')
3122+
3123+
Get level values by supplying `level` as integer:
3124+
3125+
>>> idx.get_level_values(0)
3126+
Index(['a', 'b', 'c'], dtype='object')
3127+
"""
31133128
self._validate_index_level(level)
31143129
return self
31153130

0 commit comments

Comments
 (0)