[Python] How to modify rank in pandas in python

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have a pandas dataframe as follows.

    item x1 x2 x3 x4 x5 ratings
    item1 x x x x x 46
    item1 x x x x x 32
    item1 x x x x x 16
    item1 x x x x x 6
    item1 x x x x x 36
    item1 x x x x x 36
    item1 x x x x x 12
    item1 x x x x x 13
    item1 x x x x x 41
    item1 x x x x x 42
    item1 x x x x x 43
    item1 x x x x x 3
    item1 x x x x x 76
    item1 x x x x x 36
    item1 x x x x x 26
    item1 x x x x x 12
    item1 x x x x x 11
    item1 x x x x x 88
    item1 x x x x x 87
    item1 x x x x x 78
    item1 x x x x x 43
    item1 x x x x x 42


    Now, I want to add another column with rankings of ratings.

    I did it fine using;

    df = df.assign(rankings=df.rank(ascending=False))


    I want to re-aggrange ranking column again and add a diffrent column to the dataframe as follows.

    • Rankings from 1-10 --> get rank 1
    • Rankings from 11-20 --> get rank 2
    • Rankings from 21-30 --> get rank 3
    • and so on

    Is there a way to do this in pandas in python?

    I am happy to provide more details if needed.

    Continue reading...

Compartilhe esta Página