Vectorized groupby with NumPy

前端 未结 4 2212
自闭症患者
自闭症患者 2020-12-31 08:11

Pandas has a widely-used groupby facility to split up a DataFrame based on a corresponding mapping, from which you can apply a calculation on each subgroup and recombine the

4条回答
  •  盖世英雄少女心
    2020-12-31 08:44

    There's probably a faster way than this (both of the operands are making copies right now), but:

    np.bincount(np.broadcast_to(groups, X.T.shape).ravel(), X.T.ravel())
    
    array([ 15.,  30.])
    

提交回复
热议问题