Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

# mapping module

Mapping utilities.

## apply_mapping function

    apply_mapping(
        obj,
        mapping_like=None,
        enum_unkval=-1,
        reverse=False,
        ignore_case=True,
        ignore_underscores=True,
        ignore_invalid=True,
        ignore_type=None,
        ignore_missing=False,
        na_sentinel=None
    )

Apply mapping on object using a mapping-like object.

Args

`obj` :`any`

  Any object.

  Can take a scalar, tuple, list, set, frozenset, NumPy array, Index, Series, and DataFrame.

`mapping_like` :`mapping_like`

  Any mapping-like object.

  See to_value_mapping().

`enum_unkval` :`any`
  Missing value for enumerated types.
`reverse` :`bool`
  See `reverse` in to_value_mapping().
`ignore_case` :`bool`
  Whether to ignore the case if the key is a string.
`ignore_underscores` :`bool`
  Whether to ignore underscores if the key is a string.
`ignore_invalid` :`bool`
  Whether to remove any character that is not allowed in a Python variable.
`ignore_type` :`dtype_like` or `tuple`
  One or multiple types or data types to ignore.
`ignore_missing` :`bool`
  Whether to ignore missing values.
`na_sentinel` :`any`
  Value to mark “not found”.

## reverse_mapping function

    reverse_mapping(
        mapping
    )

Reverse a mapping.

Returns a dict.

## to_field_mapping function

    to_field_mapping(
        mapping_like
    )

Convert mapping-like object to a field mapping.

## to_value_mapping function

    to_value_mapping(
        mapping_like,
        reverse=False,
        enum_unkval=-1
    )

Convert mapping-like object to a value mapping.

Enable `reverse` to apply reverse_mapping() on the result dict.

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings