[Python] Add specific Column elements conditionally based on another column in a data frame

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

  1. Stack

    Stack Membro Participativo

    I have a dataframe

    df = iteration column A Column B
    1 A 10
    1 B 20
    1 C 10
    2 D 90
    2 A 10
    2 X 40
    3 x 100
    4 5 10
    4 C 30

    I need to sum up columnB values for every iteration value in iteration column and print it out i.e

    Sum (iteration 1) = 10 + 20 + 10 = 40
    Sum (iteration 2) = 90 + 10 + 40 = 140
    Sum (iteration 3) = 100
    Sum (iteration 4) = 10 +30 = 40


    Is there any inbuilt function to achieve this in dataframes or any insights?

    Continue reading...

Compartilhe esta Página