Categorization algorithm for discrete variables
The code can be largely simplified using apply. But first, you need a better way to test your values and assign them an id:

def convert_count_to_id(count, limits=(2, 5, 10, 20, 32)):
    for id, limit in enumerate(limits, 1):
        if count &lt; limit:
            return id
    return id + 1


This is equivalent to your elifs chain but harder to get wrong.

Now your function can become:

def ramses_id_category(data):
    serie_name = 'Ramses Trade Id'
    value_ramses = data[serie_name].value_counts()
    id_ramses = values_ramses.apply(convert_count_to_id)
    data[serie_name] = data[serie_name].apply(id_ramses.get)


Note that I removed the return data at the end. Since you are mutating the parameter in place, there is no need to return it back since the caller will already be able to see the changes on the reference they hold when calling this function.