Pandas Very Simple Percent of total size from Group by

后端 未结 3 1399
不知归路
不知归路 2021-01-15 11:08

I\'m having trouble for a seemingly incredibly easy operation. What is the most succint way to just get a percent of total from a group by operation such as df.groupby

3条回答
  •  情书的邮戳
    2021-01-15 11:51

    Getting good performance (3.73s) on DF with shape (3e6,59) by using: df.groupby('col1').size().apply(lambda x: float(x) / df.groupby('col1').size().sum()*100)

提交回复
热议问题