drop_items
drop_items(x, items, trim=True)Drop unwanted answer categories from a question.
Removes specific answer values, typically catch-all or uninformative options such as “Other”, “Don’t know” or “Not applicable”, by turning them into missing values, so they fall out of counts, percentages and charts and the remaining percentages re-base on the answers you keep. The summary helpers (calc_percentage(), calc_percentage_multi(), calc_percentage_batch()) and crosstab() take a drop= argument that applies this for you before counting; set a session-wide default with ezrsurvey_options(drop_answers=...).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | list or Series | Text (or categorical) values. | required |
| items | str or list of str | Exact answer values to drop. Matching is case-insensitive. | required |
| 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 any value matching items missing. |
See Also
na_blank, calc_percentage
Examples
>>> drop_items(["Yes", "No", "Other", "Don't know"], items=["Other", "Don't know"])