Pandas - Finding percent contributed by each group

后端 未结 1 595
南方客
南方客 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)
提交回复
热议问题