Skip to content

Commit

Permalink
DOC: added examples to DataFrame.std (#44226)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruankie committed Nov 1, 2021
1 parent e8d3136 commit 33fffdb
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions pandas/core/generic.py
Expand Up @@ -10640,6 +10640,7 @@ def mad(self, axis=None, skipna=None, level=None):
name2=name2,
axis_descr=axis_descr,
notes="",
examples="",
)
def sem(
self,
Expand All @@ -10662,6 +10663,7 @@ def sem(
name2=name2,
axis_descr=axis_descr,
notes="",
examples="",
)
def var(
self,
Expand All @@ -10680,11 +10682,12 @@ 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,
notes=_std_notes,
examples=_std_examples,
)
def std(
self,
Expand Down Expand Up @@ -11176,7 +11179,8 @@ def _doc_params(cls):
Returns
-------
{name1} or {name2} (if level specified) \
{notes}
{notes}\
{examples}
"""

_std_notes = """
Expand All @@ -11186,6 +11190,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}
Expand Down

0 comments on commit 33fffdb

Please sign in to comment.