[Python] how to aggregate and sum based on some column in pandas? [duplicate]

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

  1. Stack

    Stack Membro Participativo

    i have some data in a csv format, which keeps track of items , under certain category and their count. I want to read this csv in a pandas dataframe, which i did. how do i group based on the category and add up all the numbers in the count column for each category ?

    import pandas as pd

    df = pd.read_csv('data.csv')

    ...



    id | item | category | count
    1 | Iphone | electronics | 23
    2. | laptop | electronics | 96
    3. | Books | Stationary | 487
    ...

    Continue reading...

Compartilhe esta Página