graphlab SFrame 对一列中的所有值求和

graphlab SFrame sum all values in a column

如何对 SFrame graphlab 的一列中的所有值求和。我试着查看官方文档,它只针对 SaArray(doc) 没有任何例子。

>>> import graphlab as gl
>>> sf = gl.SFrame({'foo':[1,2,3], 'bar':[4,5,6]})
>>> sf
Columns:
        bar     int
        foo     int

Rows: 3

Data:
+-----+-----+
| bar | foo |
+-----+-----+
|  4  |  1  |
|  5  |  2  |
|  6  |  3  |
+-----+-----+
[3 rows x 2 columns]
>>> sf['foo'].sum()
6

我认为操作员提出的问题更多是关于如何同时跨所有(或一系列)列执行此操作。这是 pandas 和 graphlab 之间的比较。

# imports
import graphlab as gl    
import pandas as pd
import numpy as np

# generate data
data = np.random.randint(0,10,size=100).reshape(10,10)
col_names = list('ABCDEFGHIJ')

# make dataframe and sframe
df = pd.DataFrame(data, columns=names)
sf = graphlab.SFrame(df)

# get sum for all columns (pandas).  Returns a series.
df.sum().sort_values(ascending=False)

D    65
A    61
J    59
B    50
H    46
G    46
I    45
F    43
C    37
E    36

# sf.sum() does not work
# get sum for each of the columns (graphlab)
for col in col_names:
    print col, sf[col].sum()

A 61
B 50
C 37
D 65
E 36
F 43
G 46
H 46
I 45
J 59

我也有同样的问题。 Pandas 提供了一个简单的界面来跨数据帧的行或列应用聚合函数。找不到与 SFrame 相同的内容?我能想到的唯一方法是迭代列列表。

有没有更好的方法?