From a2910ada8a4407bffc6e79f7a19eba99e78a09fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Novosz=C3=A1th?= Date: Sun, 11 Mar 2018 18:56:01 +0100 Subject: [PATCH] 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 --- pandas/core/indexes/base.py | 42 ++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index e47854d94542e..e82b641db98fd 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -681,7 +681,47 @@ def _values(self): return self.values def get_values(self): - """ return the underlying data as an ndarray """ + """ + Return `Index` data as an `numpy.ndarray`. + + Returns + ------- + numpy.ndarray + A one-dimensional numpy array of the `Index` values. + + See Also + -------- + Index.values : The attribute that get_values wraps. + + Examples + -------- + Getting the `Index` values of a `DataFrame`: + + >>> df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], + ... index=['a', 'b', 'c'], columns=['A', 'B', 'C']) + >>> df + A B C + a 1 2 3 + b 4 5 6 + c 7 8 9 + >>> df.index.get_values() + array(['a', 'b', 'c'], dtype=object) + + Standalone `Index` values: + + >>> idx = pd.Index(['1', '2', '3']) + >>> idx.get_values() + array(['1', '2', '3'], dtype=object) + + `MultiIndex` arrays also have only one dimension: + + >>> midx = pd.MultiIndex.from_arrays([[1, 2, 3], ['a', 'b', 'c']], + ... names=('number', 'letter')) + >>> midx.get_values() + array([(1, 'a'), (2, 'b'), (3, 'c')], dtype=object) + >>> midx.get_values().ndim + 1 + """ return self.values @Appender(IndexOpsMixin.memory_usage.__doc__)