[Python] Groupby by sum of revenue and the corresponding highest contributing month - Pandas

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

  1. Stack

    Stack Membro Participativo

    I have a bill details data set and I want to do a groupby of the products based on the sum of their Total value, additionally i want a column which indicates the month which has produced the most revenue for the corresponding product

    Data set:

    Bill_Id Month Product_Id Net_Value
    1 1 20 100
    2 1 20 100
    3 2 20 100
    4 1 30 200
    5 2 30 200
    6 2 30 200


    Desired_Result

    Product_Id Total_revenue Top_Month
    20 300 1
    30 600 2


    This just a sample dataset I have the transaction data of the entire year

    Continue reading...

Compartilhe esta Página