pandas.Series.std#
- Series.std(axis=None, skipna=True, ddof=1, numeric_only=False, **kwargs)[源代码]#
返回所请求轴上的样本标准差。
默认情况下按 N-1 进行归一化。可以使用 ddof 参数更改。
- Parameters:
- axis{index (0)}
对于 Series,此参数未使用,默认为 0。
警告
DataFrame.std 配合
axis=None的行为已被弃用,未来版本将对两个轴进行归约并返回标量。要保留旧行为,请传递 axis=0(或不传递 axis)。- <strong>skipna</strong>bool, default True
排除 NA/null 值。如果整行/整列都是 NA,则结果为 NA。
- ddofint, 默认值 1
Delta Degrees of Freedom。计算中使用的除数是 N - ddof,其中 N 代表元素的数量。
- numeric_onlybool,默认 False
对于 DataFrame,指定
axis=None将跨两个轴应用聚合。
- Returns:
- 标量或 Series(如果指定了 level)
Notes
要获得与 numpy.std 相同的行为,请使用 ddof=0`(而不是默认的 `ddof=1)。
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
列的标准差可以按如下方式找到:
>>> df.std() age 18.786076 height 0.237417 dtype: float64
或者,可以将 ddof=0 设置为按 N 而不是 N-1 进行归一化:
>>> df.std(ddof=0) age 16.269219 height 0.205609 dtype: float64