Python|熊猫系列.std()
Pandas 系列是带有轴标签的一维 ndarray。标签不必是唯一的,但必须是可散列的类型。该对象支持基于整数和基于标签的索引,并提供了许多用于执行涉及索引的操作的方法。
Pandas Series.std()
函数返回请求轴上的样本标准偏差。默认情况下,标准差按 N-1 归一化。这可以使用 ddof 参数进行更改。
Syntax: Series.std(axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs)
Parameter :
axis : {index (0)}
skipna : Exclude NA/null values. If an entire row/column is NA, the result will be NA
level : If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a scalar
ddof : Delta Degrees of Freedom. The divisor used in calculations is N – ddof, where N represents the number of elements.
numeric_only : boolean, default None
Returns : std : scalar or Series (if level specified)
示例 #1:使用Series.std()
函数查找给定 Series 对象的标准差。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([100, 25, 32, 118, 24, 65])
# Print the series
print(sr)
输出 :
现在我们将使用Series.std()
函数来查找给定 Series 对象的标准差。
# find standard-deviation along the
# 0th index
sr.std()
输出 :
正如我们在输出中看到的, Series.std()
函数已成功计算给定 Series 对象的标准差。示例 #2 :使用Series.std()
函数查找给定 Series 对象的标准差。我们的系列对象中有一些缺失值,因此请跳过这些缺失值。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([19.5, 16.8, None, 22.78, None, 20.124, None, 18.1002, None])
# Print the series
print(sr)
输出 :
现在我们将使用Series.std()
函数来查找给定 Series 对象的标准差。
# find standard-deviation along the
# 0th index
sr.std(skipna = True)
输出 :
正如我们在输出中看到的, Series.std()
函数已成功计算给定 Series 对象的标准差。如果我们不跳过缺失值,那么输出将为NaN
。