na_blank
na_blank(x, also=None, trim=True)Convert blank and boilerplate non-answers to missing.
Survey exports are littered with empty strings and standard “non-answer” options such as “Prefer not to answer”. This helper turns those into real missing values so they drop out of counts and summaries.
The input is converted to text (so categoricals are handled), optionally whitespace-trimmed, and any value equal to “” or to one of also becomes missing. The default also reads the na_answers option, so you can change what counts as a non-answer package-wide with ezrsurvey_options(na_answers=...). Most of the calc_* helpers call na_blank() internally when na_rm=True, so you usually get this clean-up for free.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | list or Series | Text (or categorical) values. | required |
| also | str or list of str | Additional exact strings to treat as missing. None (default) uses the na_answers option (“Prefer not to answer”); pass [] to only blank out ““. |
None |
| trim | bool | Whether to trim surrounding whitespace before comparing. Default True. | True |
Returns
| Name | Type | Description |
|---|---|---|
| pandas.Series | Text the same length as x, with blanks and non-answers missing. |
See Also
ensure_numeric, ezrsurvey_options
Examples
>>> na_blank(["Yes", "", "Prefer not to answer", "No"])
>>> na_blank(["a", "n/a", "N/A"], also=["n/a", "N/A"])