Implement label encoding for ordinal categorical variables. Given a list of category strings and a specified ordering, map each category to its integer rank. Categories not in the ordering should be assigned -1.
def label_encode(data: list[str], ordering: list[str]) -> list[int]:
label_map = {cat: idx for idx, cat in enumerate(ordering)}
return [label_map.get(val, -1) for val in data]