[Python] Consolidating data with multiple columns in Pandas [duplicate]

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

  1. Stack

    Stack Membro Participativo

    I have an excel file, with 4 columns, namely "Item", "Size", "Price", "Quantity".

    I would like to combine all the items with same value in "Item", "Size", "Price", and sum up their "Quantity" into a single entry, and keep the sorting order.

    For example:

    Item. Size. Price Quantity
    A 2-3cm 0.5 10
    A 1-2cm 0.6 20
    B 2cm 0.7 30
    A 1-2cm 0.6 40

    Desired Output:

    Item. Size. Price Quantity
    A 2-3cm 0.5 10
    A 1-2cm 0.6 60
    B 2cm 0.7 30

    I tried to use groupby method, but the results seem not correct. Any idea to solve this in excel365 + Python Pandas?

    Continue reading...

Compartilhe esta Página