Skip to content

Commit 33fffdb

Browse files
authored
DOC: added examples to DataFrame.std (#44226)
1 parent e8d3136 commit 33fffdb

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

pandas/core/generic.py

+34-2
Original file line numberDiff line numberDiff line change
@@ -10640,6 +10640,7 @@ def mad(self, axis=None, skipna=None, level=None):
1064010640
name2=name2,
1064110641
axis_descr=axis_descr,
1064210642
notes="",
10643+
examples="",
1064310644
)
1064410645
def sem(
1064510646
self,
@@ -10662,6 +10663,7 @@ def sem(
1066210663
name2=name2,
1066310664
axis_descr=axis_descr,
1066410665
notes="",
10666+
examples="",
1066510667
)
1066610668
def var(
1066710669
self,
@@ -10680,11 +10682,12 @@ def var(
1068010682
_num_ddof_doc,
1068110683
desc="Return sample standard deviation over requested axis."
1068210684
"\n\nNormalized by N-1 by default. This can be changed using the "
10683-
"ddof argument",
10685+
"ddof argument.",
1068410686
name1=name1,
1068510687
name2=name2,
1068610688
axis_descr=axis_descr,
1068710689
notes=_std_notes,
10690+
examples=_std_examples,
1068810691
)
1068910692
def std(
1069010693
self,
@@ -11176,7 +11179,8 @@ def _doc_params(cls):
1117611179
Returns
1117711180
-------
1117811181
{name1} or {name2} (if level specified) \
11179-
{notes}
11182+
{notes}\
11183+
{examples}
1118011184
"""
1118111185

1118211186
_std_notes = """
@@ -11186,6 +11190,34 @@ def _doc_params(cls):
1118611190
To have the same behaviour as `numpy.std`, use `ddof=0` (instead of the
1118711191
default `ddof=1`)"""
1118811192

11193+
_std_examples = """
11194+
11195+
Examples
11196+
--------
11197+
>>> df = pd.DataFrame({'person_id': [0, 1, 2, 3],
11198+
... 'age': [21, 25, 62, 43],
11199+
... 'height': [1.61, 1.87, 1.49, 2.01]}
11200+
... ).set_index('person_id')
11201+
>>> df
11202+
age height
11203+
person_id
11204+
0 21 1.61
11205+
1 25 1.87
11206+
2 62 1.49
11207+
3 43 2.01
11208+
11209+
The standard deviation of the columns can be found as follows:
11210+
11211+
>>> df.std()
11212+
age 18.786076
11213+
height 0.237417
11214+
11215+
Alternatively, `ddof=0` can be set to normalize by N instead of N-1:
11216+
11217+
>>> df.std(ddof=0)
11218+
age 16.269219
11219+
height 0.205609"""
11220+
1118911221
_bool_doc = """
1119011222
{desc}
1119111223

0 commit comments

Comments
 (0)