Skip to content

Commit 5304048

Browse files
DOC: added examples to DataFrame.var #44162 (#44274)
* DOC: added examples to DataFrame.std * DOC: fixed PEP compliance in DataFrame.std examples * DOC: inserted examples into docs for pandas.DataFrame.std * Update pandas/core/generic.py * Update pandas/core/generic.py * DOC: punctuation fix in pandas/core/generic.py * DOC: whitespace fix in pandas/core/generic.py * DOC: whitespace fix in pandas/core/generic.py * DOC: added two examples to the docstring of pandas.DataFrame.var * DOC: punctuation fix in docstring of pandas.DataFrame.var * DOC: minor changes to docstring of pandas.DataFrame.var Co-authored-by: Marco Edward Gorelli <[email protected]>
1 parent 969b07c commit 5304048

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

pandas/core/generic.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10674,12 +10674,12 @@ def sem(
1067410674
@doc(
1067510675
_num_ddof_doc,
1067610676
desc="Return unbiased variance over requested axis.\n\nNormalized by "
10677-
"N-1 by default. This can be changed using the ddof argument",
10677+
"N-1 by default. This can be changed using the ddof argument.",
1067810678
name1=name1,
1067910679
name2=name2,
1068010680
axis_descr=axis_descr,
1068110681
notes="",
10682-
examples="",
10682+
examples=_var_examples,
1068310683
)
1068410684
def var(
1068510685
self,
@@ -11234,6 +11234,32 @@ def _doc_params(cls):
1123411234
age 16.269219
1123511235
height 0.205609"""
1123611236

11237+
_var_examples = """
11238+
11239+
Examples
11240+
--------
11241+
>>> df = pd.DataFrame({'person_id': [0, 1, 2, 3],
11242+
... 'age': [21, 25, 62, 43],
11243+
... 'height': [1.61, 1.87, 1.49, 2.01]}
11244+
... ).set_index('person_id')
11245+
>>> df
11246+
age height
11247+
person_id
11248+
0 21 1.61
11249+
1 25 1.87
11250+
2 62 1.49
11251+
3 43 2.01
11252+
11253+
>>> df.var()
11254+
age 352.916667
11255+
height 0.056367
11256+
11257+
Alternatively, ``ddof=0`` can be set to normalize by N instead of N-1:
11258+
11259+
>>> df.var(ddof=0)
11260+
age 264.687500
11261+
height 0.042275"""
11262+
1123711263
_bool_doc = """
1123811264
{desc}
1123911265

0 commit comments

Comments
 (0)