Skip to content

Commit a2910ad

Browse files
nocibambiTomAugspurger
authored andcommitted
DOC: update the Index.get_values docstring (#20231)
* DOC: update the Index.get_values docstring * Corrections * Corrected extended summary and quotes * Correcting spaces, extended summary, multiIndex example * See also correction * Multi ndim
1 parent afa6c42 commit a2910ad

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

pandas/core/indexes/base.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,47 @@ def _values(self):
681681
return self.values
682682

683683
def get_values(self):
684-
""" return the underlying data as an ndarray """
684+
"""
685+
Return `Index` data as an `numpy.ndarray`.
686+
687+
Returns
688+
-------
689+
numpy.ndarray
690+
A one-dimensional numpy array of the `Index` values.
691+
692+
See Also
693+
--------
694+
Index.values : The attribute that get_values wraps.
695+
696+
Examples
697+
--------
698+
Getting the `Index` values of a `DataFrame`:
699+
700+
>>> df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
701+
... index=['a', 'b', 'c'], columns=['A', 'B', 'C'])
702+
>>> df
703+
A B C
704+
a 1 2 3
705+
b 4 5 6
706+
c 7 8 9
707+
>>> df.index.get_values()
708+
array(['a', 'b', 'c'], dtype=object)
709+
710+
Standalone `Index` values:
711+
712+
>>> idx = pd.Index(['1', '2', '3'])
713+
>>> idx.get_values()
714+
array(['1', '2', '3'], dtype=object)
715+
716+
`MultiIndex` arrays also have only one dimension:
717+
718+
>>> midx = pd.MultiIndex.from_arrays([[1, 2, 3], ['a', 'b', 'c']],
719+
... names=('number', 'letter'))
720+
>>> midx.get_values()
721+
array([(1, 'a'), (2, 'b'), (3, 'c')], dtype=object)
722+
>>> midx.get_values().ndim
723+
1
724+
"""
685725
return self.values
686726

687727
@Appender(IndexOpsMixin.memory_usage.__doc__)

0 commit comments

Comments
 (0)