vectorized_lookup_ordered_v1()

Apply ordered regex matching to a Pandas Series.

Usage

Source

vectorized_lookup_ordered_v1(
    series,
    mapping_df,
)

For each regex pattern in mapping_df, check if the value in series matches the pattern. The corresponding TARGET is assigned when a match is found, and later rules are skipped. Any cell that does not match any pattern retains its original value.

Parameters

series: pd.Series

The input data series (e.g., a DataFrame column).

mapping_df: pd.DataFrame

A DataFrame with at least two columns:

  • SOURCE: regex patterns (ordered by priority)
  • TARGET: corresponding replacement values

Returns

pd.Series

A new series with values replaced according to the first matching

regex, or the original value if no match is found.