Skip to content

Added two examples to documentation of DataFrame.std #44167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -11191,6 +11192,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],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put spaces between the list elements (pep)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange, all the tests passed on pre-commit. Can this be because this "code" is inside a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The passed pre-commit tests referred to in the previous comment were passed in PR #44226

... '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 Expand Up @@ -11771,7 +11800,6 @@ def _doc_params(cls):
``min_count`` non-NA values are present the result will be NA.
"""


def _align_as_utc(
left: NDFrameT, right: NDFrameT, join_index: Index | None
) -> tuple[NDFrameT, NDFrameT]:
Expand Down