search
Search
Join our weekly DS/ML newsletter layers DS/ML Guides
menu
menu search toc more_vert
Robocat
Guest 0reps
Thanks for the thanks!
close
Comments
Log in or sign up
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
help Ask a question
Share on Twitter
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
icon_star
Doc Search
icon_star
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Navigate to
A
A
brightness_medium
share
arrow_backShare
Twitter
Facebook

Pandas DataFrame | sem method

Pandas
chevron_right
Documentation
chevron_right
DataFrame
chevron_right
Basic and Descriptive Statistics
schedule Jul 1, 2022
Last updated
local_offer PythonPandas
Tags

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:

$$\sigma_\bar{X}=\frac{\sigma_X}{\sqrt{n}}$$

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. axislink | int or string | optional

Whether to compute the statistic row-wise or column-wise:

Axis

Description

Compute the SEM for each column.

0 or "index"

Compute the SEM for each row.

0 or "columns"

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:

$$\sigma_{X}^2=\frac{1}{N{\color{#6495ed}-ddof}}\sum_{i=0}^{N}\left(x_i-\bar{x}^2\right)$$

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 = pd.DataFrame({"A":[2,5,8], "B":[4,5,6]}, index=["a","b","c"])
df
   A  B
a  2  4
b  5  5
c  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.732051
B 0.577350
dtype: 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.0
b 0.0
c 1.0
dtype: float64
mail
Join our newsletter for updates on new DS/ML comprehensive guides (spam-free)
robocat
Published by Isshin Inada
Edited by 0 others
Did you find this page useful?
thumb_down
Ask a question or leave a feedback...
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!