def filter_rare_cards(df, rarity_num=5, card_column='CRD_NO', date_column='dates'):
    """
    Removes rare cards. Takes only cards which have more than rarity_num bills (different days)
    Args:
        df: Dataframe with bills
        rarity_num: Minimum num bills per crd
        card_column: Column that contains crd number
        date_column: Column that contains date
    Returns:
    Filtered DataFrame
    """
    # drop_duplicates - Чтобы оставить только уникальные пары карта-день
    # (смотреть сколько разных дней покупатель приходил)
    cards_num_bills = df.drop_duplicates([date_column, card_column])\
                        .groupby([card_column]).size().reset_index(name='bill_counts')
    df = df.merge(cards_num_bills, on=card_column, how='left')
    return df[df['bill_counts'] > rarity_num].drop('bill_counts', axis=1)