Pandas groupby: percentage above threshold

后端 未结 1 1785
孤街浪徒
孤街浪徒 2021-01-12 02:23

I have a DataFrame that I\'m looking to use a groupby on but I\'m looking for a little bit of an unusual function to aggregate with. I would like to get the per

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 02:49

    >>> df.groupby('day')['value'].apply(lambda c: (c>0).sum()/len(c))
    day
    1      0.333333
    2      0.666667
    3      0.333333
    4      1.000000
    Name: value, dtype: float64
    

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