[Python] How do I sum values in a column that match a given condition using pandas?

Discussão em 'Python' iniciado por Stack, Abril 6, 2025.

  1. Stack

    Stack Membro Participativo

    Suppose I have a dataframe like so:

    a b
    1 5
    1 7
    2 3
    1 3
    2 5


    I want to sum up the values for b where a = 1, for example. This would give me 5 + 7 + 3 = 15.

    How do I do this in pandas?

    Continue reading...

Compartilhe esta Página