# GraphLab Create™ Translator

The GraphLab Create API is easy to learn and use. See how to convert code syntax from products you already know to GraphLab Create.

### Constructing data objects

Task Construct a one-dimensional vector Construct a vector with missing values GraphLab Create (ver. 1.0) Pandas (ver. 0.15.0) R (ver. 3.1.1) sa = gl.SArray([1, 2, 3, 4]) s = pd.Series([1, 2, 3, 4]) s = c(1, 2, 3, 4) sa = gl.SArray([1, 3, 5, None, 6]) s = pd.Series([1, 3, 5, np.nan, 6]) s = c(1, 3, 5, NaN, 6) sf = gl.SFrame({'type': ['cat', 'fossa'], 'height': [15., 23.5]}) df = pd.DataFrame({'type': ['cat', 'fossa'], 'height': [15., 23.5]}) df = data.frame(type=c('cat', 'fossa'), height=c(15, 23.5)) sg = gl.SGraph() df = sf.to_dataframe() sf = gl.SFrame(df)

Task Retrieve a single column from a table Retrieve multiple columns from a table GraphLab Create (ver. 1.0) Pandas (ver. 0.15.0) R (ver. 3.1.1) sf['A'] df['A'] df$A sf[['A', 'C']] df[['A', 'C']] df[c('A', 'C')] sf[3] df.iloc[3] df[4, ] sf[3:7] df[3:7] df[4:7, ] sf['A'][3] df.at[3, 'A'] df$A[4] sf[3:7][['A', 'C']] df.loc[3:6, ['A', 'C']] df[4:7, c('A', 'C')] sf.filter_by(['b', 'd', 'f'], 'type') df[df['type'].isin(['b', 'd', 'f'])] subset(df, df$type %in% c('b', 'd', 'f')) sf[sf['A'] > 0.5] df[df.A > 0.5] subset(df, df$A > .5) df.at[3, 'A'] = -1 df$A[4] = -1 ### Vector arithmetic Task Add two vectors Subtract two vectors GraphLab Create (ver. 1.0) Pandas (ver. 0.15.0) R (ver. 3.1.1) sf['A'] + sf['B'] df['A'] + df['B'] df$A + df$B sf['A'] - sf['B'] df['A'] - df['B'] df$A - df$B sf['A'] * sf['B'] df['A'] * df['B'] df$A * df$B sf['A'] / sf['B'] df['A'] / df['B'] df$A / df$B sf['A'].apply(lambda x: x**2) df['A']**2 df$A^2 sf['C'] == sf['D'] df['C'] == df['D'] df$C == df$D sf['C'] <= sf['D'] sf['C'] >= sf['D'] df['C'] <= df['D'] df['C'] >= df['D'] df$C <= df$D df$C >= df$D

Task Read a binary data file Read data from a text file GraphLab Create (ver. 1.0) Pandas (ver. 0.15.0) R (ver. 3.1.1) sf = gl.load_sframe("my_sframe") df = pd.read_pickle("my_dataframe") load('my_dataframe.rdata') sf = gl.SFrame.read_csv('my_sframe.csv') df = pd.read_csv('my_dataframe.csv') df = read.csv('my_dataframe.csv') sf.save('my_sframe', format='csv') df.to_csv('my_dataframe.csv', index=False) write.csv(df, file='my_dataframe.csv') sf.save('my_sframe') df.to_pickle('my_dataframe') save(df, file='my_dataframe.rdata')
Task Get the first rows of a table Get the last rows of a table GraphLab Create (ver. 1.0) Pandas (ver. 0.15.0) R (ver. 3.1.1) sf.head(5) df.head(5) head(df, n=5) sf.tail(5) df.tail(5) tail(df, n=5) sf.print_rows(30) pd.set_option('display.max_rows', 30) df df sf.column_names() df.columns colnames(df) sf.column_types() df.dtypes lapply(df, class) sf = sf.add_row_number() sf['id'] df.index rownames(df) sf['new'] = range(sf.num_rows()) df['new'] = range(len(df)) df$new = 1:nrow(df) sf.remove_column('new') df = df.drop('new', axis=1) df[, names(df) != 'new'] sf2 = sf[['A', 'B']] sf2.add_columns(sf[['C']]) blocks = [df[['A', 'B']], df[['C']]] df2 = pd.concat(blocks, axis=1) df2 = cbind(df[,c('A','B')], 'C'=df$C) sf.join(sf2) pd.merge(df, df2) merge(df, df2) sf.append(sf2) df.append(df2) rbind(df, df2) sf.pack_columns(['A', 'B', 'C'], dtype=dict) sf.unpack('value_dict') sf.stack('value_dict', new_column_name=['type', 'value']) sf.pack_columns(['A', 'B', 'C'], dtype=dict, new_column_name='value_dict').stack('value_dict') df.stack() sf.unstack(['type', 'value'], new_column_name='value_dict').unpack('value_dict') df.unstack()