replace_variable_values#

Survey.replace_variable_values(column_selection: str | int | list | ndarray | Series | range | Callable[[SurveyVariable], bool] | None = None, mapping: dict | list | None = None, change_type_to: str | None = None, combine_labels_if_not_injective: bool = True, suppress_check_var_warning: bool = False)#

Replace the values found in the selected columns by different values. This does change the data and the variable’s metadata.

The corresponding value labels (in the variable_info of this object) are retained.

Parameters#

column_selectionstr, int, list, np.ndarray, pd.Series, range, QuestionSelector or None

If None, all columns are taken into account. Otherwise, a subset will be considered. The parameter is interpreted as described in Survey.interpret_column_selection().

mappingdict, list or None

An object providing replacement values.

  • If mapping is None, values are replaced by integers in order of the natural sorting order of the old values.

  • If mapping is a list, the values are mapped to their indices in this list.

  • If mapping is a dictionary, the values are mapped to the new values given in the dictionary.

change_type_tostr, optional

Optionally change the type of the changed columns.

combine_labels_if_not_injectivebool

if multiple values are mapped to the same value, their labels are combined

suppress_check_var_warningbool

If True, don’t show a warning if there are ‘unusable’ variables. A variable is unusable, if we can not automatically create features for the corresponding question.