[Python] Adding previous rows to generate another row in pandas

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

  1. Stack

    Stack Membro Participativo

    I am trying to solve a problem in my data-frame

    df.head()
    0 Key value
    1 10 500
    2 11 500
    3 12 600
    4 12 800
    5 13 1000
    6 13 1200
    .
    .
    .
    200++


    output is to put the values in the above data-frame or have another data-frame with all the values of above with additional info show as below.

    Expected Output:

    0 Key value
    1 10 500
    2 11 500
    3 12 600
    4 12 800
    5 12 1400 -----> Addition of 800+600 as keys are same
    6 13 1000
    7 13 1200
    8 13 2200 -----> Addition of 1000+12000 as keys are same
    .
    .
    200++


    I am just starting out in Pandas, any help will be appreciate.

    Continue reading...

Compartilhe esta Página