Pandas - Finding percent contributed by each group

后端 未结 1 596
南方客
南方客 2021-01-28 01:48

I am trying to find the percentage contribution made by each date group. Given below is how my data looks like.

Expecting to find contribution of each product for a given

1条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-28 02:04

    Use groupby().transform():

    df['quantity'] / df.groupby('date')['quantity'].transform('sum')
    

    0 讨论(0)
提交回复
热议问题