def rare_species(df, frequency_threshold=10, target_column='species_id', filter_out=True):
    """Operation to filter rare species, i.e species with a frequency that is below a threshold."""
    target_serie = df[target_column]
    # get frequency of specie for every occurrence
    counts = target_serie.map(target_serie.value_counts())
    mask = counts < frequency_threshold
    if filter_out:
        mask = ~mask
    return df[mask].copy()