Fire up GraphLab Create

We always start with this line before using any part of GraphLab Create


In [ ]:
import graphlab

Load a tabular data set


In [1]:
sf = graphlab.SFrame('people-example.csv')


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-4df0be298ea8> in <module>()
----> 1 sf = graphlab.SFrame('people-example.csv')

NameError: name 'graphlab' is not defined

SFrame basics


In [ ]:
sf #we can view first few lines of table

In [ ]:
sf.tail()  # view end of the table

GraphLab Canvas


In [ ]:
# .show() visualizes any data structure in GraphLab Create
sf.show()

In [ ]:
# If you want Canvas visualization to show up on this notebook, 
# rather than popping up a new window, add this line:
graphlab.canvas.set_target('ipynb')

In [ ]:
sf['age'].show(view='Categorical')

Inspect columns of dataset


In [ ]:
sf['Country']

In [ ]:
sf['age']

Some simple columnar operations


In [ ]:
sf['age'].mean()

In [ ]:
sf['age'].max()

Create new columns in our SFrame


In [ ]:
sf

In [ ]:
sf['Full Name'] = sf['First Name'] + ' ' + sf['Last Name']

In [ ]:
sf

In [ ]:
sf['age'] * sf['age']

Use the apply function to do a advance transformation of our data


In [ ]:
sf['Country']

In [ ]:
sf['Country'].show()

In [ ]:
def transform_country(country):
    if country == 'USA':
        return 'United States'
    else:
        return country

In [ ]:
transform_country('Brazil')

In [ ]:
transform_country('Brasil')

In [ ]:
transform_country('USA')

In [ ]:
sf['Country'].apply(transform_country)

In [ ]:
sf['Country'] = sf['Country'].apply(transform_country)

In [ ]:
sf

In [ ]: