2016-07-20 3 views
4

Comment utiliser l'opération groupby dans SFrame, sans installer graphlab. Je voudrais faire une certaine agrégation, mais dans tous les exemples sur Internet, j'ai vu la fonction d'agrégation vient de Graphlab.Regrouper par SFrame sans installer graphlab

Comme:

import graphlab.aggregate as agg 

user_rating_stats = sf.groupby(key_columns='user_id', 
          operations={ 
           'mean_rating': agg.MEAN('rating'), 
           'std_rating': agg.STD('rating') 
          }) 

Comment puis-je utiliser, par exemple, numpy.mean et non agg.MEAN dans l'exemple ci-dessus?

Répondre

3

Le package sframe contient le même module d'agrégation que le package graphlab, vous ne devriez donc pas avoir besoin de recourir à 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]