search
Search
Login
Unlock 100+ guides
menu
menu
web
search toc
close
Comments
Log in or sign up
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
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

Pandas DataFrame | sem method

schedule Aug 10, 2023
Last updated
local_offer
PythonPandas
Tags
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
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:

$$\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

0 or "index"

Compute the SEM for each column.

0 or "columns"

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:

$$\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
robocat
Published by Isshin Inada
Edited by 0 others
Did you find this page useful?
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!