from typing import Counter


def remove_unpopulated_classes(_df, target_column, threshold):
    """
    Removes any row of the df for which the label in target_column appears less
    than threshold times in the whole frame (not enough populated classes)
    :param df: The dataframe to filter
    :param target_column: The target column with labels
    :param threshold: the number of appearances a label must respect
    :return: The filtered dataframe
    """
    count = Counter(_df[target_column])
    valid = [k for k in count.keys() if count[k] >= threshold]
    _df = _df[_df[target_column].isin(valid)]
    return _df