Skip to content

Commit fe2f525

Browse files
committed
DOC: Improve the docstring of Index.get_level_values
1 parent 5b0caf4 commit fe2f525

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

pandas/core/indexes/base.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -2788,26 +2788,45 @@ def set_value(self, arr, key, value):
27882788

27892789
def _get_level_values(self, level):
27902790
"""
2791+
Return an Index of values for requested level, specially useful for
2792+
MultiIndex.
2793+
27912794
Return an Index of values for requested level, equal to the length
2792-
of the index.
2795+
of the index. This is mainly useful for MultiIndex.
27932796
27942797
Parameters
27952798
----------
27962799
level : int or str
2797-
``level`` is either the integer position of the level in the
2798-
MultiIndex, or the name of the level.
2800+
It is either the integer position or the name of the level.
2801+
If given as an integer, it must be between 0 and the
2802+
number of levels - 1.
27992803
28002804
Returns
28012805
-------
28022806
values : Index
2803-
``self``, as there is only one level in the Index.
2807+
`self`, as there is only one level in the Index.
28042808
28052809
See also
28062810
---------
28072811
pandas.MultiIndex.get_level_values : get values for a level of a
28082812
MultiIndex
2809-
"""
28102813
2814+
Notes
2815+
---------
2816+
For Index, level should be 0, since there are no multiple levels.
2817+
2818+
Examples
2819+
---------
2820+
2821+
>>> idx = pd.Index(list('abc'))
2822+
>>> idx
2823+
Index(['a', 'b', 'c'], dtype='object')
2824+
2825+
Get level value by supplying level as integer:
2826+
2827+
>>> idx.get_level_values(0)
2828+
Index(['a', 'b', 'c'], dtype='object')
2829+
"""
28112830
self._validate_index_level(level)
28122831
return self
28132832

0 commit comments

Comments
 (0)