From 57af7eff283d4cc1b2ce55618a09a9811fc6cdc2 Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Sun, 24 Oct 2021 18:12:46 +0200 Subject: [PATCH 1/3] added examples template for DataFrame.std --- pandas/core/generic.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c3ad87082c8ed..bac7eeaf7e8da 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10685,10 +10685,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( @@ -11771,6 +11772,10 @@ def _doc_params(cls): ``min_count`` non-NA values are present the result will be NA. """ +_std_examples = """ +Examples +-------- +""" def _align_as_utc( left: NDFrameT, right: NDFrameT, join_index: Index | None From b34e18b58234ffa4198237970bd12aea13ccc0f5 Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Sun, 24 Oct 2021 18:34:13 +0200 Subject: [PATCH 2/3] added example for DataFrame.std --- pandas/core/generic.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index bac7eeaf7e8da..ce8bab491524a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11192,6 +11192,28 @@ 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 +""" + _bool_doc = """ {desc} @@ -11772,11 +11794,6 @@ def _doc_params(cls): ``min_count`` non-NA values are present the result will be NA. """ -_std_examples = """ -Examples --------- -""" - def _align_as_utc( left: NDFrameT, right: NDFrameT, join_index: Index | None ) -> tuple[NDFrameT, NDFrameT]: From 8d5b31b664144cf073c3a1bd84f4b8bb39097f82 Mon Sep 17 00:00:00 2001 From: Ruan Pretorius Date: Sun, 24 Oct 2021 18:40:01 +0200 Subject: [PATCH 3/3] added example to DataFrame.std docs --- pandas/core/generic.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ce8bab491524a..6e0e74249f61b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11212,6 +11212,12 @@ def _doc_params(cls): >>> 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 = """