calc_summary

calc_summary(data=None, column=None, by=None, na_rm=True, weights=None)

Summarise a numeric question (mean / median / sd).

The numeric counterpart to calc_percentage(), with optional grouping. The column is passed through ensure_numeric() first, so a text age column like “25 years” still summarises. n counts non-missing values (after that coercion). When a weighting scheme is active the statistics are weighted (and missing values are dropped); n remains the unweighted respondent count. For a measure of how precise the mean is, pair this with diagnose() or se_mean().

Parameters

Name Type Description Default
data pandas.DataFrame A data frame. If omitted, the session default is used. None
column str Numeric column to summarise. None
by str or list of str Grouping column(s); see calc_percentage(). None
na_rm bool Drop missing values before summarising. Default True. True
weights (bool, dict or list) Survey weighting: None (default) uses the session scheme from set_weights() if set; False forces unweighted; or pass an ad-hoc scheme. When weighting is active the mean, median and sd become their weighted versions (n stays the unweighted base). None

Returns

Name Type Description
pandas.DataFrame n (non-missing count), mean, median and sd, one row per group when by is supplied.

See Also

calc_percentage, diagnose

Examples

>>> calc_summary(podracing_survey, "demo_age")
>>> calc_summary(podracing_survey, "demo_age", by="region")