graphlab安装
graphlab目前支持python2.7 所以安装python最好先安装
import graphlab as gl
gl.get_dependencies()
启动jupyter notebook[gl-env]
应用 新开页面表格
import graphlab
sf = graphlab.SFrame('goods_list.csv')
# print(sf)
# print(sf.head(4))
print(sf.show())
在本地开页面
import graphlab
graphlab.canvas.set_target('ipynb')
sf['ghP'].show(view='Categorical')
操作列数据
显示一列
计算平均值 最大值
sf['age'].mean()
sf['age'].max()
增加新列
sf['fullnam'] = sf['First Name'] + ' ' + sf['Last Name']
sf['age'] + 2
sf['age'] * sf['age']
应用apply函数来转换数据
sf['country']
def transform_country(country):
if country == "USA":
return 'United States'
else:
return country
transform_country('Barzil')
transform_country('USA')
sf['country'].apply(transform_country) #转换了 还没有赋值回原数列
sf['country'] = sf['country'].apply(transform_country)