Complete worked example
python
import pandas as pd
def inspect_example(values):
text = pd.Series(values, dtype="string")
country = text.str.strip().str.upper()
has_hyphen = text.str.contains("-", regex=False, na=False).astype("boolean")
return pd.DataFrame({"country": country, "has_hyphen": has_hyphen})- Reasoning
- Create a nullable text Series, then chain str.strip and str.upper to produce a canonical display code. Use str.contains with regex=False when the search term is literal punctuation. Set na=False only for the output flag, preserving missing values in the normalized text itself. Build the two-column result from aligned Series with matching row indexes. Trace whitespace around ua, a missing entry and the value il-central. Normalized values become UA, missing and IL-CENTRAL. The hyphen flag is true only for the last row. The normalizer does not decide whether a resulting code is an accepted country; an allowlist belongs to a later selection rule.