vectorized_lookup_ordered_v2()
Apply ordered matching (regex or exact) to a Pandas Series.
Usage
vectorized_lookup_ordered_v2(
series,
mapping_df,
)For each row in mapping_df:
- If ``IS_REGEX`` is True, perform regex matching.
- If ``IS_REGEX`` is False, perform exact string matching.
The corresponding TARGET is assigned when a match is found, and later rules are skipped. Any cell that does not match 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 three columns:
SOURCE: regex patterns or exact strings (ordered by priority)TARGET: corresponding replacement valuesIS_REGEX: boolean indicating whether SOURCE is a regex
Returns
pd.Series-
A new series with values replaced according to the first matching
rule, or the original value if no match is found.