From 470dc0659a98c75b2cbb2ee846f51c6c74499b03 Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Fri, 29 Oct 2021 12:53:14 +0200 Subject: [PATCH 01/11] DOC: added examples to DataFrame.std --- pandas/core/generic.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7ff48a262c4d6..d2d2a06f7fe84 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10679,10 +10679,11 @@ def var( _num_ddof_doc, desc="Return sample standard deviation over requested axis." "\n\nNormalized by N-1 by default. This can be changed using the " - "ddof argument", + "ddof argument.", name1=name1, name2=name2, axis_descr=axis_descr, + examples=_std_examples, notes=_std_notes, ) def std( @@ -11185,6 +11186,34 @@ def _doc_params(cls): To have the same behaviour as `numpy.std`, use `ddof=0` (instead of the default `ddof=1`)""" +_std_examples = """ +Examples +-------- +>>> df = pd.DataFrame({'person_id':[0,1,2,3], +... 'age':[21,25,62,43], +... 'height':[1.61,1.87,1.49,2.01]} +... ).set_index('person_id') +>>> df + age height +person_id +0 21 1.61 +1 25 1.87 +2 62 1.49 +3 43 2.01 + +The standard deviation of the columns can be found as follows. + +>>> df.std() +age 18.786076 +height 0.237417 + +Alternatively, `ddof=0` can be set to normalize by N instead of N-1. + +>>> df.std(ddof=0) +age 16.269219 +height 0.205609 +""" + _bool_doc = """ {desc} From b003dc9caffbff9255ab9432bc8bdd5460504adc Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Fri, 29 Oct 2021 14:48:19 +0200 Subject: [PATCH 02/11] DOC: fixed PEP compliance in DataFrame.std examples --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d2d2a06f7fe84..890e8e80ed3c9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11189,9 +11189,9 @@ def _doc_params(cls): _std_examples = """ Examples -------- ->>> df = pd.DataFrame({'person_id':[0,1,2,3], -... 'age':[21,25,62,43], -... 'height':[1.61,1.87,1.49,2.01]} +>>> df = pd.DataFrame({'person_id': [0, 1, 2, 3], +... 'age': [21, 25, 62, 43], +... 'height': [1.61, 1.87, 1.49, 2.01]} ... ).set_index('person_id') >>> df age height From 44b0ddf2d533e03fb51da3314a425f92a18afb99 Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Mon, 1 Nov 2021 13:57:55 +0200 Subject: [PATCH 03/11] DOC: inserted examples into docs for pandas.DataFrame.std --- pandas/core/generic.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 890e8e80ed3c9..540bfa8c00680 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10639,6 +10639,7 @@ def mad(self, axis=None, skipna=None, level=None): name2=name2, axis_descr=axis_descr, notes="", + examples="", ) def sem( self, @@ -10661,6 +10662,7 @@ def sem( name2=name2, axis_descr=axis_descr, notes="", + examples="", ) def var( self, @@ -10683,8 +10685,8 @@ def var( name1=name1, name2=name2, axis_descr=axis_descr, - examples=_std_examples, notes=_std_notes, + examples=_std_examples, ) def std( self, @@ -11177,6 +11179,8 @@ def _doc_params(cls): ------- {name1} or {name2} (if level specified) \ {notes} + +{examples} """ _std_notes = """ @@ -11186,7 +11190,7 @@ def _doc_params(cls): To have the same behaviour as `numpy.std`, use `ddof=0` (instead of the default `ddof=1`)""" -_std_examples = """ +_std_examples = """\ Examples -------- >>> df = pd.DataFrame({'person_id': [0, 1, 2, 3], From 2740a13acd8b00104790daa2310c6c9e7186b493 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Mon, 1 Nov 2021 12:06:47 +0000 Subject: [PATCH 04/11] Update pandas/core/generic.py --- 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 540bfa8c00680..476010dd9dd3b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11205,7 +11205,7 @@ def _doc_params(cls): 2 62 1.49 3 43 2.01 -The standard deviation of the columns can be found as follows. +The standard deviation of the columns can be found as follows: >>> df.std() age 18.786076 From d637fa47ea6659b5996426f46e8514870b621e57 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Mon, 1 Nov 2021 12:06:51 +0000 Subject: [PATCH 05/11] Update pandas/core/generic.py --- 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 476010dd9dd3b..7debad6eb0933 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11211,7 +11211,7 @@ def _doc_params(cls): age 18.786076 height 0.237417 -Alternatively, `ddof=0` can be set to normalize by N instead of N-1. +Alternatively, `ddof=0` can be set to normalize by N instead of N-1: >>> df.std(ddof=0) age 16.269219 From 858f1af9fe7094cd2e932ee4021e12e0a219a81d Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Mon, 1 Nov 2021 14:10:58 +0200 Subject: [PATCH 06/11] DOC: punctuation fix in pandas/core/generic.py --- 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 540bfa8c00680..7debad6eb0933 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11205,13 +11205,13 @@ def _doc_params(cls): 2 62 1.49 3 43 2.01 -The standard deviation of the columns can be found as follows. +The standard deviation of the columns can be found as follows: >>> df.std() age 18.786076 height 0.237417 -Alternatively, `ddof=0` can be set to normalize by N instead of N-1. +Alternatively, `ddof=0` can be set to normalize by N instead of N-1: >>> df.std(ddof=0) age 16.269219 From cd1a646429a625fa14156466b16c27ac984eaf39 Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Mon, 1 Nov 2021 14:29:28 +0200 Subject: [PATCH 07/11] DOC: whitespace fix in pandas/core/generic.py --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7debad6eb0933..f6ce66708504a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11178,8 +11178,7 @@ def _doc_params(cls): Returns ------- {name1} or {name2} (if level specified) \ -{notes} - +{notes}\ {examples} """ @@ -11190,7 +11189,8 @@ def _doc_params(cls): To have the same behaviour as `numpy.std`, use `ddof=0` (instead of the default `ddof=1`)""" -_std_examples = """\ +_std_examples = """ + Examples -------- >>> df = pd.DataFrame({'person_id': [0, 1, 2, 3], From 93293c135d5b8215fffc8352d53c494c493274b5 Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Mon, 1 Nov 2021 17:38:55 +0200 Subject: [PATCH 08/11] DOC: whitespace fix in pandas/core/generic.py --- pandas/core/generic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f6ce66708504a..c2fa345f7639d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11215,8 +11215,7 @@ def _doc_params(cls): >>> df.std(ddof=0) age 16.269219 -height 0.205609 -""" +height 0.205609""" _bool_doc = """ {desc} From 9ca0137323a5638c1ed8ddc1b36eb85b77bdf5b8 Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Mon, 1 Nov 2021 21:05:39 +0200 Subject: [PATCH 09/11] DOC: added two examples to the docstring of pandas.DataFrame.var --- 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 c2fa345f7639d..32e8434d17608 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10662,7 +10662,7 @@ def sem( name2=name2, axis_descr=axis_descr, notes="", - examples="", + examples=_var_examples, ) def var( self, @@ -11217,6 +11217,34 @@ def _doc_params(cls): age 16.269219 height 0.205609""" +_var_examples = """ + +Examples +-------- +>>> df = pd.DataFrame({'person_id': [0, 1, 2, 3], +... 'age': [21, 25, 62, 43], +... 'height': [1.61, 1.87, 1.49, 2.01]} +... ).set_index('person_id') +>>> df + age height +person_id +0 21 1.61 +1 25 1.87 +2 62 1.49 +3 43 2.01 + +The variance of the columns can be found as follows: + +>>> df.var() +age 352.916667 +height 0.056367 + +Alternatively, `ddof=0` can be set to normalize by N instead of N-1: + +>>> df.var(ddof=0) +age 264.687500 +height 0.042275""" + _bool_doc = """ {desc} From c243c5ee4a87926f11b75381214626625128b4b7 Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Tue, 2 Nov 2021 11:34:23 +0200 Subject: [PATCH 10/11] DOC: punctuation fix in docstring of pandas.DataFrame.var --- 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 69b52f7473500..b49a3edbac565 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10661,7 +10661,7 @@ def sem( @doc( _num_ddof_doc, desc="Return unbiased variance over requested axis.\n\nNormalized by " - "N-1 by default. This can be changed using the ddof argument", + "N-1 by default. This can be changed using the ddof argument.", name1=name1, name2=name2, axis_descr=axis_descr, From e583e0f20a0f4a59de1082e2fc1c4004b245439e Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Sat, 6 Nov 2021 10:13:25 +0200 Subject: [PATCH 11/11] DOC: minor changes to docstring of pandas.DataFrame.var --- pandas/core/generic.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b49a3edbac565..cbfbd62975692 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11237,13 +11237,11 @@ def _doc_params(cls): 2 62 1.49 3 43 2.01 -The variance of the columns can be found as follows: - >>> df.var() age 352.916667 height 0.056367 -Alternatively, `ddof=0` can be set to normalize by N instead of N-1: +Alternatively, ``ddof=0`` can be set to normalize by N instead of N-1: >>> df.var(ddof=0) age 264.687500