pydit.wrangling.map_common_values.map_values

pydit.wrangling.map_common_values.map_values(df: DataFrame, input_column: str, output_column: str, mapping: str, na_action=None, case: str = 'lower')[source]

Map common values to more descriptive values or values that are easier to sort/present/filter on.

Parameters:
  • df (pd.DataFrame) – The dataframe to map values on

  • input_column (str) – The column to map values from

  • output_column (str) – The column to map values to

  • mapping (str) –

    One of the following pre defined mappings:
    • ”high_medium_low”

    • ”red_yellow_green”

    • ”red_yellow_green_blue”

    • ”red_amber_green”

    • ”red_amber_yellow_green”

    Suffixing _r will do a reverse the order of numeric mapping. e.g. “high_medium_low_r” will map to 3, 2, 1 e.g. “red_yellow_green_r” will map to 3, 2, 1

    Prefixing to_ will do a mapping to the value. e.g. “to_high_medium_low” will map 1, 2, 3 to “high”, “medium”, “low” e.g. “to_high_medium_low_r” will map 1, 2, 3 to “low”, “medium”, “high”

  • na_action (str, optional, default None) – Parameter to pass to the pandas map function. See pandas documentation

  • case (str, optional, default "lower") – The output case to use for the mapping. One of “lower”, “upper”, “title”, “capitalize”