In [2]:
import graphlab
In [3]:
sf = graphlab.SFrame('people-example.csv')
In [26]:
sf #We can view first few lines of table
Out[26]:
In [5]:
sf.tail() # view end of the table
Out[5]:
In [6]:
# .show() visualizes any data structure in GraphLab Create
sf.show()
In [7]:
# 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 [27]:
sf['age'].show(view='Numeric')
In [9]:
sf['Country']
Out[9]:
In [10]:
sf['age']
Out[10]:
Some simple columnar operations
In [31]:
sf['age'].mean()
Out[31]:
In [12]:
sf['age'].max()
Out[12]:
In [13]:
sf
Out[13]:
In [14]:
sf['Full Name'] = sf['First Name'] + ' ' + sf['Last Name']
In [15]:
sf
Out[15]:
In [16]:
sf['age'] * sf['age']
Out[16]:
In [17]:
sf['Country']
Out[17]:
In [18]:
sf['Country'].show()
In [32]:
def transform_country(country):
if country == 'United States':
return 'USA'
else:
return country
In [20]:
transform_country('Brazil')
Out[20]:
In [21]:
transform_country('Brasil')
Out[21]:
In [22]:
transform_country('USA')
Out[22]:
In [33]:
sf['Country'].apply(transform_country)
Out[33]:
In [35]:
sf['Country'] = sf['Country'].apply(transform_country)
In [36]:
sf
Out[36]:
In [46]:
sf[0]['Country'] = 'United States'
In [51]:
sf
Out[51]:
In [ ]: