python - 选择 SFrame 中的特定行

标签 python graphlab sframe

我对如何选择 SFrame 数组中的特定行感到困惑。我可以在此处选择第一行:

sf
+-------------------------------+
|               X1              |
+-------------------------------+
| [0.0, 0.0, 0.0, 0.0, 0.0, ... |
[100 rows x 1 columns]

sf[:1]
+-------------------------------+
|               X1              |
+-------------------------------+
| [0.0, 0.0, 0.0, 0.0, 0.0, ... |
[1 rows x 1 columns]

sf[:2]
+-------------------------------+
|               X1              |
+-------------------------------+
| [0.0, 0.0, 0.0, 0.0, 0.0, ... |
| [0.0, 0.0, 0.0, 0.0, 0.0, ... |
[2 rows x 1 columns]

type(sf[:1])
graphlab.data_structures.sframe.SFrame

这里我试图只获取第 2 行

sf[:,2]
# TypeError: Invalid key type: must be str, bytes or type

如何选择数据框中的任何行?

最佳答案

您可以选择一行:

import graphlab as gl
sf = gl.SFrame({'a':[1,2,3], 'b':[2,9,1]})
# select first row
print sf[0]
# select second row
print sf[1] 
# and so on
# convert first row to an SFrame
sf_one_raw = sf[0:1]
# convert second row to an SFrame
sf_one_raw = sf[1:2]

关于python - 选择 SFrame 中的特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38044536/

相关文章:

python-2.7 - 如何在 Ubuntu 上安装 Graphlab Create?

python - SFrame 中的字符串对象到日期时间对象

python - 调用函数在 python 中使用 .apply

pandas - Pandas 中是否有 GraphLab SFrame.show() 等价物?

python - 根据一些给定的引用元素插入颜色矩阵的元素

python - 如何在 django 模板中呈现有序字典?

python - pandas - 如何合并 DataFrame 中的选定行

python - 如何将 pyglet opengl 上下文集成到 gtk3 glarea 中?

python - 种子选项 : Using different packages for machine learning in Python

python - graphlab:如何将 gzip 压缩文件加载到 SFrame 中