[Python] Group the same column value and sum columns value in a different column [duplicate]

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I have a dataframe

    df =
    Workload Value Data
    0 1 1 X
    1 1 2 Y
    2 1 3 Z
    3 1 4 X
    4 1 5 X
    5 2 6 Z
    6 2 7 X
    7 2 8 Y
    8 2 9 Z
    9 2 10 X


    I need to group by Column=Workload and add the values in "Value" Column and exclude displaying other columns.

    Output df

    df =
    Workload Value
    1 15
    2 40


    Any insights how we can achieve this. I tried groupby(), pivot(), but nothing seems to the rigth approach.

    Continue reading...

Compartilhe esta Página