Pandas DataFrame | sem method
Start your free 7-days trial now!
Pandas DataFrame.sem(~)
method returns the unbiased standard error of the mean for each row or column of the source DataFrame.
Note that the unbiased standard error of the mean is defined as follows:
Where,
$\sigma_\bar{X}$ is the unbiased standard error of the mean
$\sigma_X$ is the unbiased sample standard deviation (normalized by $n-1$ by default).
$n$ is the sample size (number of values in a column or row).
Parameters
1. axis
link | int
or string
| optional
Whether to compute the statistic row-wise or column-wise:
Axis | Description |
---|---|
| Compute the SEM for each column. |
| Compute the SEM for each row. |
By default, axis=0
.
2. skipna
| boolean
| optional
Whether or not to ignore NaN
. By default, skipna=True
.
3. level
| int
or string
| optional
The level to target if the source DataFrame is a multi-index.
4. ddof
| int
| optional
The delta degree of freedom. This can be used to modify the denominator ddof
of the sample variance:
By default, ddof=1
. Note that $\sigma_X$ is used to compute the SEM.
Return Value
If the level
parameter is specified, then a DataFrame
will be returned. Otherwise, a Series
will be returned.
Examples
Consider the following DataFrame:
df
A Ba 2 4b 5 5c 8 6
Computing SEM of each column
By default, axis=0
, which means that we compute the SEM of each column:
df.sem()
A 1.732051B 0.577350dtype: float64
Computing SEM of each row
To compute the SEM of each row instead, pass in axis=1
like so:
df.sem(axis=1)
a 1.0b 0.0c 1.0dtype: float64