clarite.modify.recode_values¶
-
clarite.modify.
recode_values
(data, replacement_dict, skip: Union[str, List[str], NoneType] = None, only: Union[str, List[str], NoneType] = None)¶ Convert values in a dataframe. By default, replacement occurs in all columns but this may be modified with ‘skip’ or ‘only’. Pandas has more powerful ‘replace’ methods for more complicated scenarios.
Parameters: - data: pd.DataFrame
The DataFrame to be processed and returned
- replacement_dict: dictionary
A dictionary mapping the value being replaced to the value being inserted
- skip: str, list or None (default is None)
List of variables that the replacement should not be applied to
- only: str, list or None (default is None)
List of variables that the replacement should only be applied to
Examples
>>> import clarite >>> clarite.modify.recode_values(df, {7: np.nan, 9: np.nan}, only=['SMQ077', 'DBD100']) ================================================================================ Running recode_values -------------------------------------------------------------------------------- Replaced 17 values from 22,624 observations in 2 variables >>> clarite.modify.recode_values(df, {10: 12}, only=['SMQ077', 'DBD100']) ================================================================================ Running recode_values -------------------------------------------------------------------------------- No occurences of replaceable values were found, so nothing was replaced.