[Python] changing sort in value_counts

Discussão em 'Python' iniciado por Stack, Fevereiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    If I do

    mt = mobile.PattLen.value_counts() # sort True by default


    I get

    4 2831
    3 2555
    5 1561
    [...]


    If I do

    mt = mobile.PattLen.value_counts(sort=False)


    I get

    8 225
    9 120
    2 1234
    [...]


    What I am trying to do is get the output in 2, 3, 4 ascending order (the left numeric column). Can I change value_counts somehow or do I need to use a different function.

    Continue reading...

Compartilhe esta Página