def reduce_categorical_options(df, max_options=10, feature_of_interest='town'):
    """
    Allow for a maximum number of most frequent categorical values and replace all other with value "Other"
    This assumes the type of categorical values is string
    """
    if feature_of_interest not in df.columns:
        print('feature not in dataframe')
        return df
    allowed = df[feature_of_interest].value_counts().head(max_options).index.tolist()
    df[feature_of_interest] = df[feature_of_interest].apply(lambda x: x if x in allowed else 'Other')
    return df