In [1]:
import graphlab
In [2]:
sf = graphlab.SFrame('../data/books/book-data.csv')
In [3]:
sf # We can view first few lines of table
Out[3]:
In [4]:
sf.tail() # view end of the table
Out[4]:
In [5]:
# .show() visualizes any data structure in GraphLab Create
sf.show()
In [6]:
# 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 [7]:
sf['year'].show(view='Categorical')
In [8]:
sf['author']
Out[8]:
In [9]:
sf['year']
Out[9]:
Some simple columnar operations
In [10]:
sf['year'].mean()
Out[10]:
In [11]:
sf['year'].max()
Out[11]:
In [12]:
sf
Out[12]:
In [13]:
sf['full_name'] = sf['book'] + ' ' + sf['author'] + ' ' + sf['publisher']
In [14]:
sf
Out[14]:
In [16]:
sf['year'] + 2
Out[16]:
In [17]:
sf['year'].show()
In [18]:
def transform_year(year):
if (year > 1945) and (year < 2016):
return year
else:
return None
In [22]:
print transform_year(1960)
In [21]:
print transform_year(2022)
In [24]:
print transform_year(1900)
In [27]:
sf['year'].apply(transform_year)
Out[27]:
In [28]:
sf['year'] = sf['year'].apply(transform_year)
In [30]:
sf['year'].show()
In [ ]: