[Python] Conditionally transform values of each group in pandas

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

  1. Stack

    Stack Membro Participativo

    I have a dataframe as following:


    Year-Week Ticket Policy User
    2022-35 12502 COMPLIED MX
    2022-35 12502 NOT COMPLIED US
    2022-35 12502 COMPLIED AL
    2022-35 12502 COMPLIED BR
    2022-35 12471 COMPLIED DE
    2022-35 12409 COMPLIED US
    2022-35 12409 NOT COMPLIED BR
    2022-35 12406 COMPLIED MX


    When there are duplicate tickets, how could I standardize that each ticket has the same policy? E.g: If a ticket in a week has "NOT COMPLIED", the policy should be the same for that ticket no matter the week, so, should be something like this:

    Output Sample


    Year-Week Ticket Policy User
    2022-35 12502 NOT COMPLIED MX
    2022-35 12502 NOT COMPLIED US
    2022-35 12502 NOT COMPLIED AL
    2022-35 12502 NOT COMPLIED BR
    2022-35 12471 COMPLIED DE
    2022-35 12409 NOT COMPLIED US
    2022-35 12409 NOT COMPLIED BR
    2022-35 12406 COMPLIED MX


    Basically what I want is the dominance of NOT COMPLIED over COMPLIED when there are duplicated Tickets.

    Continue reading...

Compartilhe esta Página