Skip to content

Commit

Permalink
DOC: Improved the docstring of pandas.DataFrame.values (pandas-dev#20065
Browse files Browse the repository at this point in the history
)
  • Loading branch information
math-and-data authored and jorisvandenbossche committed Mar 10, 2018
1 parent 840d432 commit 8497029
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4232,7 +4232,55 @@ def as_matrix(self, columns=None):

@property
def values(self):
"""Numpy representation of NDFrame
"""
Return a Numpy representation of the DataFrame.
Only the values in the DataFrame will be returned, the axes labels
will be removed.
Returns
-------
numpy.ndarray
The values of the DataFrame.
Examples
--------
A DataFrame where all columns are the same type (e.g., int64) results
in an array of the same type.
>>> df = pd.DataFrame({'age': [ 3, 29],
... 'height': [94, 170],
... 'weight': [31, 115]})
>>> df
age height weight
0 3 94 31
1 29 170 115
>>> df.dtypes
age int64
height int64
weight int64
dtype: object
>>> df.values
array([[ 3, 94, 31],
[ 29, 170, 115]], dtype=int64)
A DataFrame with mixed type columns(e.g., str/object, int64, float32)
results in an ndarray of the broadest type that accommodates these
mixed types (e.g., object).
>>> df2 = pd.DataFrame([('parrot', 24.0, 'second'),
... ('lion', 80.5, 1),
... ('monkey', np.nan, None)],
... columns=('name', 'max_speed', 'rank'))
>>> df2.dtypes
name object
max_speed float64
rank object
dtype: object
>>> df2.values
array([['parrot', 24.0, 'second'],
['lion', 80.5, 1],
['monkey', nan, None]], dtype=object)
Notes
-----
Expand All @@ -4243,8 +4291,13 @@ def values(self):
e.g. If the dtypes are float16 and float32, dtype will be upcast to
float32. If dtypes are int32 and uint8, dtype will be upcast to
int32. By numpy.find_common_type convention, mixing int64 and uint64
will result in a flot64 dtype.
int32. By :func:`numpy.find_common_type` convention, mixing int64
and uint64 will result in a float64 dtype.
See Also
--------
pandas.DataFrame.index : Retrievie the index labels
pandas.DataFrame.columns : Retrieving the column names
"""
self._consolidate_inplace()
return self._data.as_array(transpose=self._AXIS_REVERSED)
Expand Down

0 comments on commit 8497029

Please sign in to comment.