Pandas Very Simple Percent of total size from Group by

后端 未结 3 1363
不知归路
不知归路 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条回答
  •  -上瘾入骨i
    2021-01-15 11:49

    I don't know if I'm missing something, but looks like you could do something like this:

    df.groupby('A').size() * 100 / len(df)
    

    or

    df.groupby('A').size() * 100 / df.shape[0]
    

提交回复
热议问题