Skip to content

Commit b9e52d1

Browse files
DOC: Enforce Numpy Docstring Validation for pandas.DataFrame.std (#58564)
* DOC: add PR01,RT03,SA01 for pandas.DataFrame.std * DOC: remove PR01,RT03,SA01 for pandas.DataFrame.std * DOC: add PR01,RT03,SA01 for pandas.DataFrame.std * DOC: add Series.std for pandas.DataFrame.std
1 parent 30dabf4 commit b9e52d1

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7575
-i "pandas.DataFrame.median RT03,SA01" \
7676
-i "pandas.DataFrame.min RT03" \
7777
-i "pandas.DataFrame.plot PR02,SA01" \
78-
-i "pandas.DataFrame.std PR01,RT03,SA01" \
7978
-i "pandas.DataFrame.swaplevel SA01" \
8079
-i "pandas.Grouper PR02" \
8180
-i "pandas.Index PR07" \

pandas/core/frame.py

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12299,7 +12299,6 @@ def std(
1229912299
) -> Series | Any: ...
1230012300

1230112301
@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="std")
12302-
@doc(make_doc("std", ndim=2))
1230312302
def std(
1230412303
self,
1230512304
axis: Axis | None = 0,
@@ -12308,6 +12307,82 @@ def std(
1230812307
numeric_only: bool = False,
1230912308
**kwargs,
1231012309
) -> Series | Any:
12310+
"""
12311+
Return sample standard deviation over requested axis.
12312+
12313+
Normalized by N-1 by default. This can be changed using the ddof argument.
12314+
12315+
Parameters
12316+
----------
12317+
axis : {index (0), columns (1)}
12318+
For `Series` this parameter is unused and defaults to 0.
12319+
12320+
.. warning::
12321+
12322+
The behavior of DataFrame.std with ``axis=None`` is deprecated,
12323+
in a future version this will reduce over both axes and return a scalar
12324+
To retain the old behavior, pass axis=0 (or do not pass axis).
12325+
12326+
skipna : bool, default True
12327+
Exclude NA/null values. If an entire row/column is NA, the result
12328+
will be NA.
12329+
ddof : int, default 1
12330+
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
12331+
where N represents the number of elements.
12332+
numeric_only : bool, default False
12333+
Include only float, int, boolean columns. Not implemented for Series.
12334+
**kwargs : dict
12335+
Additional keyword arguments to be passed to the function.
12336+
12337+
Returns
12338+
-------
12339+
Series or scalar
12340+
Standard deviation over requested axis.
12341+
12342+
See Also
12343+
--------
12344+
Series.std : Return standard deviation over Series values.
12345+
DataFrame.mean : Return the mean of the values over the requested axis.
12346+
DataFrame.mediam : Return the mediam of the values over the requested axis.
12347+
DataFrame.mode : Get the mode(s) of each element along the requested axis.
12348+
DataFrame.sum : Return the sum of the values over the requested axis.
12349+
12350+
Notes
12351+
-----
12352+
To have the same behaviour as `numpy.std`, use `ddof=0` (instead of the
12353+
default `ddof=1`)
12354+
12355+
Examples
12356+
--------
12357+
>>> df = pd.DataFrame(
12358+
... {
12359+
... "person_id": [0, 1, 2, 3],
12360+
... "age": [21, 25, 62, 43],
12361+
... "height": [1.61, 1.87, 1.49, 2.01],
12362+
... }
12363+
... ).set_index("person_id")
12364+
>>> df
12365+
age height
12366+
person_id
12367+
0 21 1.61
12368+
1 25 1.87
12369+
2 62 1.49
12370+
3 43 2.01
12371+
12372+
The standard deviation of the columns can be found as follows:
12373+
12374+
>>> df.std()
12375+
age 18.786076
12376+
height 0.237417
12377+
dtype: float64
12378+
12379+
Alternatively, `ddof=0` can be set to normalize by N instead of N-1:
12380+
12381+
>>> df.std(ddof=0)
12382+
age 16.269219
12383+
height 0.205609
12384+
dtype: float64
12385+
"""
1231112386
result = super().std(
1231212387
axis=axis, skipna=skipna, ddof=ddof, numeric_only=numeric_only, **kwargs
1231312388
)

0 commit comments

Comments
 (0)