import re


def string_to_column_name(x: str) -> str:
    """
    Converts non-alphanumeric characters to "_" and lowercases string. Repeated
    non-alphanumeric characters are replaced with a single "_".

    Args:
        x: String to convert to column name

    Returns:
        Re-formatted string for using as a PySpark DataFrame column name
    """
    return re.sub("[^0-9a-zA-Z]+", "_", x).lower()