calc_nps
calc_nps(data=None, value=None, by=None, weights=None)Net Promoter Score.
Computes NPS from a 0-10 recommendation question. Respondents are bucketed by nps_group() into detractors (0-6), passives (7-8) and promoters (9-10); the score is the percentage of promoters minus the percentage of detractors, which equals 100 * mean() of the signed -1/0/1 coding. Missing or out-of-range scores are dropped before the mean. Text answers are coerced with ensure_numeric().
The three group counts and shares are reported alongside the score because a single NPS hides how it was reached: +20 from 40% promoters and 20% detractors is a different picture from +20 with 25% and 5%. Counts are always unweighted respondent counts; the shares follow nps, so they are weighted when a weighting scheme is active. All three shares and nps are rounded to whole numbers independently, so pct_promoters - pct_detractors can land one point away from nps.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | pandas.DataFrame | A data frame. If omitted, the session default is used. | None |
| value | str | The 0-10 recommendation column. | None |
| by | str or list of str | Grouping column(s); see calc_percentage(). |
None |
| 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 nps is the weighted score (n stays the unweighted base). |
None |
Returns
| Name | Type | Description |
|---|---|---|
| pandas.DataFrame | n (valid responses), nps (-100 to 100), the three group shares (pct_detractors, pct_passives, pct_promoters) and the counts behind them (detractors, passives, promoters), one row per group when by is given. |
See Also
nps_group, plot_nps, plot_nps_gauge
Examples
>>> calc_nps(podracing_survey, "nps_value")
>>> calc_nps(podracing_survey, "nps_value", by="region")