In [2]:
import graphlab
In [3]:
sf = graphlab.SFrame('people-example.csv')
In [6]:
# View first few lines of table
sf
Out[6]:
In [7]:
# sf.head() works the same as Unix 'head'
sf.head(1)
Out[7]:
In [8]:
# sf.tail() works the same as Unix 'tail'
sf.tail(2)
Out[8]:
In [9]:
# Show the data with GraphLab Create
sf.show()
In [11]:
graphlab.canvas.set_target('ipynb')
In [12]:
sf['age'].show(view='Categorical')
In [13]:
sf['Country']
Out[13]:
In [14]:
sf['age']
Out[14]:
In [16]:
sf['age'].mean()
Out[16]:
In [17]:
sf['age'].max()
Out[17]:
In [21]:
# Often called feature engineering
sf['Full Name'] = sf['First Name'] + ' ' + sf['Last Name']
In [22]:
sf
Out[22]:
In [23]:
sf['Country']
Out[23]:
In [24]:
sf['Country'].show()
In [25]:
def transform_country(country):
if country == 'USA':
return 'United States'
else:
return country
In [26]:
transform_country('Brazil')
Out[26]:
In [27]:
transform_country('USA')
Out[27]:
In [28]:
sf['Country'].apply(transform_country)
Out[28]:
In [30]:
sf['Country'] = sf['Country'].apply(transform_country)
sf['Country']
Out[30]:
In [31]:
sf['Country'].show()