Skip to content

DOC: update the Index.get_level_values docstring #20210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3090,26 +3090,41 @@ def set_value(self, arr, key, value):

def _get_level_values(self, level):
"""
Return an Index of values for requested level, equal to the length
of the index.
Return an Index of values for requested level.

This is primarily useful to get an individual level of values from a
MultiIndex, but is provided on Index as well for compatability.

Parameters
----------
level : int or str
``level`` is either the integer position of the level in the
MultiIndex, or the name of the level.
It is either the integer position or the name of the level.

Returns
-------
values : Index
``self``, as there is only one level in the Index.
Calling object, as there is only one level in the Index.

See also
---------
pandas.MultiIndex.get_level_values : get values for a level of a
MultiIndex
"""
--------
MultiIndex.get_level_values : get values for a level of a MultiIndex

Notes
-----
For Index, level should be 0, since there are no multiple levels.

Examples
--------

>>> idx = pd.Index(list('abc'))
>>> idx
Index(['a', 'b', 'c'], dtype='object')

Get level values by supplying `level` as integer:

>>> idx.get_level_values(0)
Index(['a', 'b', 'c'], dtype='object')
"""
self._validate_index_level(level)
return self

Expand Down