[Python] pandas remap new two columns based other column

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

  1. Stack

    Stack Membro Participativo

    I have a pandas table where I want to create a new column and fill data based on other column values.

    I also want to know, if the new column value is updated

    I have dictionary like this:

    update_values = {"Groub_A": {"aadff2": "Mark", "aasd12": "Otto", "asdd2": "Jhon"},"Groub_B": {"aadfaa": "Josh", "aa1113": "Math", "967323sd": "Marek"}}


    And I want to my table look like this:

    Column_1 | Column_new_2 | Column_new_3
    aadff2 | Mark | Groub_A
    aadff2 | Mark | Groub_A
    aasd12 | Otto | Groub_A
    asdd2 | Jhon | Groub_A
    967323sd | Marek | Groub_B
    967323sd | Marek | Groub_B
    aa1113 | Math | Groub_B


    So far I have just copied Column_1 and use:

    df.replace("Column_new_2":update_values["Groub_A"])


    and the same thing with groub_B, but then don't know how to make it to Column_new_3

    There must be a easy solution, but I just can't figure it out.

    Continue reading...

Compartilhe esta Página