2016-07-20 8 views
4

Wie Verwenden von Groupby-Operation in SFrame, ohne Installieren von Graphlab.Gruppieren von in SFrame ohne Installieren von graphlab

Ich würde gerne etwas Aggregation machen, aber in allen Beispielen im Internet habe ich gesehen, Aggregation Funktion kommt von Graphlab.

Like:

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') 
          }) 

Wie kann ich, sagen wir, numpy.mean und nicht agg.MEAN im obigen Beispiel?

Antwort

3

Das sframe Paket enthält das gleiche Aggregationsmodul wie das graphlab Paket, Sie sollten also nicht auf numpy zurückgreifen müssen.

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] 
Verwandte Themen