pandas.core.groupby.DataFrameGroupBy.sem#

DataFrameGroupBy.sem(ddof=1, numeric_only=False)[source] #

Compute standard error of the mean of groups, excluding missing values.

For multiple groupings, the result index will be a MultiIndex.

Parameters:
ddofint, default 1

Degrees of freedom.

numeric_onlybool, default False

Include only float, int or boolean data.

Added in version 1.5.0.

Changed in version 2.0.0: numeric_only now defaults to False.

Returns:
Series or DataFrame

Standard error of the mean of values within each group.

Examples

For SeriesGroupBy:

>>> lst = ['a', 'a', 'b', 'b']
>>> ser = pd.Series([5, 10, 8, 14], index=lst)
>>> ser
a 5
a 10
b 8
b 14
dtype: int64
>>> ser.groupby(level=0).sem()
a 2.5
b 3.0
dtype: float64

For DataFrameGroupBy:

>>> data = [[1, 12, 11], [1, 15, 2], [2, 5, 8], [2, 6, 12]]
>>> df = pd.DataFrame(data, columns=["a", "b", "c"],
...  index=["tuna", "salmon", "catfish", "goldfish"])
>>> df
 a b c
 tuna 1 12 11
 salmon 1 15 2
 catfish 2 5 8
goldfish 2 6 12
>>> df.groupby("a").sem()
 b c
a
1 1.5 4.5
2 0.5 2.0

For Resampler:

>>> ser = pd.Series([1, 3, 2, 4, 3, 8],
...  index=pd.DatetimeIndex(['2023年01月01日',
...  '2023年01月10日',
...  '2023年01月15日',
...  '2023年02月01日',
...  '2023年02月10日',
...  '2023年02月15日']))
>>> ser.resample('MS').sem()
2023年01月01日 0.577350
2023年02月01日 1.527525
Freq: MS, dtype: float64