pandas.core.groupby.GroupBy.std

Compute standard deviation of groups, excluding missing values.

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

param ddof
integer, default 1

degrees of freedom

return

Series or DataFrame Standard deviation of values within each group.

Limitations

  • This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff between staying in JIT-region with that function or going back to interpreter mode.

Examples

Compute standard deviation of groups, excluding missing values.
import pandas as pd
from numba import njit


@njit
def df_groupby_std():
    df = pd.DataFrame({'A': [1, 2, 3, 1, 2, 3, 3, 3, 2],
                       'B': [0, 1, 5, 0, 2, 4, 3, 2, 3],
                       'C': [1, 2, 3, 4, 5, 6, 7, 8, 9]})
    out_df = df.groupby('A').std()

    # Expect DataFrame of
    # {'B': [0.000000, 1.000000, 1.290994], 'C': [2.121320, 3.511885, 2.160247} with index=[1, 2, 3]
    return out_df


print(df_groupby_std())
$ python ./dataframe/groupby/dataframe_groupby_std.py
          B         C
1  0.000000  2.121320
2  1.000000  3.511885
3  1.290994  2.160247

See also

Series.groupby

Group Series using a mapper or by a Series of columns.

DataFrame.groupby

Group DataFrame using a mapper or by a Series of columns.