sframe包包含与graphlab包相同的聚合模块,因此您不需要求助于numpy.
import sframe
import sframe.aggregate as agg
sf = sframe.SFrame({'user_id': [1, 1, 2],
'rating': [3.3, 3.6, 4.1]})
grp = sf.groupby('user_id', {'mean_rating': agg.MEAN('rating'),
'std_rating': agg.STD('rating')})
print(grp)
+---------+---------------------+-------------+
| user_id | std_rating | mean_rating |
+---------+---------------------+-------------+
| 2 | 0.0 | 4.1 |
| 1 | 0.15000000000000024 | 3.45 |
+---------+---------------------+-------------+
[2 rows x 3 columns]