def number_past_loans(df):
    """
    count number of past loans

    :param df: previous loans application dataframe

    :return  dataframe : SK_ID_CURR plus feature NUMBER_PREVIOUS_LOANS
    """
    df = df.groupby(['SK_ID_CURR'])['SK_ID_PREV'].count().reset_index(). \
        rename(columns={'SK_ID_PREV': 'NUMBER_PREVIOUS_LOANS'})
    return df