From 8ae58056292aee9226330d04c6b5df55ebba505d Mon Sep 17 00:00:00 2001 From: Gjelt Date: Fri, 9 Mar 2018 01:59:28 +0100 Subject: [PATCH 1/9] DOC: Improved the docstring of pandas.core.generic.NDFrame.values --- pandas/core/generic.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a893b2ba1a189..80f6121cd98df 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4232,7 +4232,35 @@ def as_matrix(self, columns=None): @property def values(self): - """Numpy representation of NDFrame + """ + Generate and return a Numpy representation of NDFrame. + + Only the values in the NDFrame will be returned, the axes labels will + be removed. + + Returns + ------- + numpy.ndarray + The values of the NDFrame + + 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')) + >>> df + name class max_speed + 0 falcon bird 389.0 + 1 parrot bird 24.0 + 2 lion mammal 80.5 + 3 monkey mammal NaN + >>> df.values + array([['falcon', 'bird', 389.0], + ['parrot', 'bird', 24.0], + ['lion', 'mammal', 80.5], + ['monkey', 'mammal', nan]], dtype=object) Notes ----- From 3fc43980b6c97496c864bd6242c9cf6d53e6f9bc Mon Sep 17 00:00:00 2001 From: Gjelt Date: Fri, 9 Mar 2018 22:08:27 +0100 Subject: [PATCH 2/9] DOC: Improved the docstring of pandas.DataFrame.values used feedback from PR to improve it --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 80f6121cd98df..b0fb458b73fa1 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4233,9 +4233,9 @@ def as_matrix(self, columns=None): @property def values(self): """ - Generate and return a Numpy representation of NDFrame. + Return a Numpy representation of the DataFrame. - Only the values in the NDFrame will be returned, the axes labels will + Only the values in the DataFrame will be returned, the axes labels will be removed. Returns From 3af7b886d89d88daafef36de106466a4cc12616e Mon Sep 17 00:00:00 2001 From: Gjelt Date: Fri, 9 Mar 2018 22:16:15 +0100 Subject: [PATCH 3/9] DOC: Improved the docstring of pandas.DataFrame.values included function reference --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b0fb458b73fa1..d2c2c09dba852 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4271,7 +4271,7 @@ 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 + int32. By :func:`numpy.find_common_type` convention, mixing int64 and uint64 will result in a flot64 dtype. """ self._consolidate_inplace() From c6607ebf6a5c22f287c3b02aa16c3ef63bce68d4 Mon Sep 17 00:00:00 2001 From: Gjelt Date: Fri, 9 Mar 2018 22:21:10 +0100 Subject: [PATCH 4/9] DOC: Improved the docstring of pandas.DataFrame.values --- pandas/core/generic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d2c2c09dba852..c764ae8cacce9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4235,8 +4235,8 @@ def values(self): """ Return a Numpy representation of the DataFrame. - Only the values in the DataFrame will be returned, the axes labels will - be removed. + Only the values in the DataFrame will be returned, the axes labels + will be removed. Returns ------- @@ -4271,8 +4271,8 @@ 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. + int32. By :func:`numpy.find_common_type` convention, mixing int64 + and uint64 will result in a flot64 dtype. """ self._consolidate_inplace() return self._data.as_array(transpose=self._AXIS_REVERSED) From 41a26910900e9651f79db82c1fc3a1b7b55afc85 Mon Sep 17 00:00:00 2001 From: Gjelt Date: Fri, 9 Mar 2018 22:38:52 +0100 Subject: [PATCH 5/9] DOC: Improved the docstring of pandas.DataFrame.values replaced NDFrame by DataFrame --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c764ae8cacce9..4da9f6bdc17f2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4241,7 +4241,7 @@ def values(self): Returns ------- numpy.ndarray - The values of the NDFrame + The values of the DataFrame Examples -------- From 4d510e175c9ae1c3fa2afc772dbf99fa8a6ab54d Mon Sep 17 00:00:00 2001 From: Gjelt Date: Sat, 10 Mar 2018 01:01:57 +0100 Subject: [PATCH 6/9] DOC: Improved the docstring of pandas.DataFrame.values --- pandas/core/generic.py | 51 +++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4da9f6bdc17f2..6dc99a937c8b7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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. + + >>> 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 - 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 + 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 ----- @@ -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) From 3b1027dc016bb41bae2093f08053e24721b70cd7 Mon Sep 17 00:00:00 2001 From: Gjelt Date: Sat, 10 Mar 2018 01:03:16 +0100 Subject: [PATCH 7/9] DOC: Improved the docstring of pandas.DataFrame.values --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6dc99a937c8b7..14a14c28648ff 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4291,7 +4291,7 @@ def values(self): See Also -------- - pandas.DataFrame.from_records : Creating a DataFrame from a numpy.ndarray + pandas.DataFrame.from_records : Creating a DataFrame from an ndarray pandas.DataFrame.keys : Retrieving the 'info axis' (column names) pandas.DataFrame.columns : Retrieving the column names """ From 7650e103a9a29c8bb54776e2a437162db6b893eb Mon Sep 17 00:00:00 2001 From: Gjelt Date: Sat, 10 Mar 2018 14:42:18 +0100 Subject: [PATCH 8/9] DOC: DataFrame.values grammar, user friendly text --- pandas/core/generic.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 14a14c28648ff..f146f54503aa5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4246,7 +4246,7 @@ def values(self): Examples -------- A DataFrame where all columns are the same type (e.g., int64) results - in an ndarray of the same type. + in an array of the same type. >>> df = pd.DataFrame({'age': [ 3, 29], ... 'height': [94, 170], @@ -4255,13 +4255,18 @@ def values(self): 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 encompasing these mixed - types (e.g., object). + 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), @@ -4291,7 +4296,8 @@ def values(self): See Also -------- - pandas.DataFrame.from_records : Creating a DataFrame from an ndarray + pandas.DataFrame.from_records : Inverse operation; creating a + DataFrame from an ndarray pandas.DataFrame.keys : Retrieving the 'info axis' (column names) pandas.DataFrame.columns : Retrieving the column names """ From ca17a1578cc7e99e81c289a8de11198346bc77cb Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sat, 10 Mar 2018 15:40:39 +0100 Subject: [PATCH 9/9] remove from_records --- pandas/core/generic.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f146f54503aa5..9f2112729a503 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4241,7 +4241,7 @@ def values(self): Returns ------- numpy.ndarray - The values of the DataFrame + The values of the DataFrame. Examples -------- @@ -4296,9 +4296,7 @@ def values(self): See Also -------- - pandas.DataFrame.from_records : Inverse operation; creating a - DataFrame from an ndarray - pandas.DataFrame.keys : Retrieving the 'info axis' (column names) + pandas.DataFrame.index : Retrievie the index labels pandas.DataFrame.columns : Retrieving the column names """ self._consolidate_inplace()