select_prefix
select_prefix(data=None, prefix=None, keep=None)Select identifier and prefixed columns.
Keeps a handful of id columns plus every column sharing a prefix in one call. Survey questionnaires are usually organised by prefix (demo_, ratings_, partner_, …), so this is a quick way to grab one block plus a couple of id columns without naming every variable. Order is keep first, then the prefix-matching columns in their original order.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | pandas.DataFrame | A data frame. If omitted, the session default is used. | None |
| prefix | str or list of str | One or more column-name prefixes to keep (e.g. “demo_”, or ["demo_", "ratings_"]). |
None |
| keep | str or list of str | Additional column names to retain in front of the prefixed block (e.g. an id column). | None |
Returns
| Name | Type | Description |
|---|---|---|
| pandas.DataFrame | The keep columns followed by all prefix-matching columns. |
See Also
read_folder, calc_percentage_multi
Examples
>>> select_prefix(podracing_survey, "demo_", keep="respondent_id")
>>> select_prefix(podracing_survey, ["ratings_", "partner_"])