[Python] how custom sort of rows in polars

Discussão em 'Python' iniciado por Stack, Agosto 12, 2025.

  1. Stack

    Stack Membro Participativo

    How to sort row with spesific order

    df = pl.DataFrame({"currency": ["EUR","EUR","EUR","USD","USD","USD"], "alphabet": ["A","B","C","A","B","C"]})


    i need to descending the currency and custom sort of alphabet

    expected to be like this

    shape: (6, 2)
    ┌──────────┬──────────┐
    │ currency ┆ alphabet │
    │ --- ┆ --- │
    │ str ┆ str │
    ╞══════════╪══════════╡
    │ USD ┆ C │
    │ USD ┆ A │
    │ USD ┆ B │
    │ EUR ┆ C │
    │ EUR ┆ A │
    │ EUR ┆ B │
    └──────────┴──────────┘

    Continue reading...

Compartilhe esta Página