-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
DOC: Improved the docstring of pandas.DataFrame.values #20065
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
Changes from 1 commit
8ae5805
3fc4398
3af7b88
c6607eb
41a2691
4d510e1
3b1027d
7650e10
ca17a15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4245,22 +4245,37 @@ def values(self): | |
|
||
Examples | ||
-------- | ||
>>> df = pd.DataFrame([('falcon', 'bird', 389.0), | ||
... ('parrot', 'bird', 24.0), | ||
... ('lion', 'mammal', 80.5), | ||
... ('monkey', 'mammal', np.nan)], | ||
... columns=('name', 'class', 'max_speed')) | ||
A DataFrame where all columns are the same type (e.g., int64) results | ||
in an ndarray of the same type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use here 'array' instead of 'ndarray' (that looks a bit more user friendly, the full name is already in the Returns section |
||
|
||
>>> df = pd.DataFrame({'age': [ 3, 29], | ||
... 'height': [94, 170], | ||
... 'weight': [31, 115]}) | ||
>>> df | ||
name class max_speed | ||
0 falcon bird 389.0 | ||
1 parrot bird 24.0 | ||
2 lion mammal 80.5 | ||
3 monkey mammal NaN | ||
age height weight | ||
0 3 94 31 | ||
1 29 170 115 | ||
>>> df.values | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you show here |
||
array([['falcon', 'bird', 389.0], | ||
['parrot', 'bird', 24.0], | ||
['lion', 'mammal', 80.5], | ||
['monkey', 'mammal', nan]], dtype=object) | ||
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 encompasing these mixed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The note belows uses "accommodates" instead of "encompasing". Best to use the same terminolgy in both cases |
||
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], | ||
72CB | ['monkey', nan, None]], dtype=object) | |
|
||
Notes | ||
----- | ||
|
@@ -4272,7 +4287,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 :func:`numpy.find_common_type` convention, mixing int64 | ||
and uint64 will result in a flot64 dtype. | ||
and uint64 will result in a float64 dtype. | ||
|
||
See Also | ||
-------- | ||
pandas.DataFrame.from_records : Creating a DataFrame from a numpy.ndarray | ||
pandas.DataFrame.keys : Retrieving the 'info axis' (column names) | ||
pandas.DataFrame.columns : Retrieving the column names | ||
""" | ||
self._consolidate_inplace() | ||
return self._data.as_array(transpose=self._AXIS_REVERSED) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
from_array
could be a good option for aSee Also
section. If I'm not wrong it's kind of the inverse method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with
from_records
, thank you for suggesting to include the inverse in that section.