Python|熊猫 dataframe.sem()
Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。
Pandas dataframe.sem()
函数返回请求轴上平均值的无偏标准误差。统计量的标准误差 (SE)(通常是参数的估计值)是其抽样分布的标准偏差 [1] 或该标准偏差的估计值。如果参数或统计量是平均值,则称为平均值的标准误差(SEM)。
Syntax : DataFrame.sem(axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs)
Parameters :
axis : {index (0), columns (1)}
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 Series
ddof : Delta Degrees of Freedom. The divisor used in calculations is N – ddof, where N represents the number of elements.
numeric_only : Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series
Return : sem : Series or DataFrame (if level specified)
有关代码中使用的 CSV 文件的链接,请单击此处
示例 #1:使用sem()
函数查找给定数据帧在索引轴上的平均值的标准误差。
# importing pandas as pd
import pandas as pd
# Creating the dataframe
df = pd.read_csv("nba.csv")
# Print the dataframe
df
让我们使用dataframe.sem()
函数来查找索引轴上平均值的标准误差。
# find standard error of the mean of all the columns
df.sem(axis = 0)
输出 :
请注意,所有非数字列和值都不会自动包含在数据框的计算中。我们不必专门输入数字列来计算平均值的标准误差。示例 #2:使用sem()
函数查找列轴上平均值的标准误差。也不要在数据帧的计算中跳过NaN
值。
# importing pandas as pd
import pandas as pd
# Creating the dataframe
df = pd.read_csv("nba.csv")
# Calculate the standard error of
# the mean of all the rows in dataframe
df.sem(axis = 1, skipna = False)
输出 :
当我们包含NaN
值时,它将导致该特定行或列成为NaN