[Python] Sort a polars dataframe based on an external list

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    Morning,

    I'm not sure if this can be achieved..

    Let's say i have a polars dataframe with cols a, b (whatever).

    df = pl.DataFrame({"a":[1,2,3,4,5],"b":['x','y','z','p','f']})


    And a list.. l = [1,3,5,2,4]; is it possible to sort the dataframe (using column "a") using the list l as the sorting order?

    Thanks in advance!

    Continue reading...

Compartilhe esta Página