Graphlab SFrame sums all the values โ€‹โ€‹in a column

How to sum all the values โ€‹โ€‹in a column of an SFrame graph. I tried to look at the official documentation and it is provided only for SaArray ( doc ) without any examples.

+4
source share
2 answers
>>> 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
+3
source

I think the question from op was more about how to do this through all (or a list of) columns at once. Here is a comparison between pandas and 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? , , - .

?

0

Source: https://habr.com/ru/post/1653348/


All Articles