sframe - 为单个 SFrame 元素分配一个值

标签 sframe

我想为 SFrame 中的单个元素(即单行和列)分配一个值。 我正在使用 Python Notebook 并导入 graphlab。

我创建了一个尺寸为 16364 行 x 37 列的 SFrame。 “测试”列包含零。

我使用以下语法来设置值: sf[1]['测试'] = 3;

如果我输入: sf[1]['测试']

then I see the correct value, i.e "3"

但是如果我输入: 顺丰

then I just see values of zero for all rows of column 'test'

对于 sf.head() 或 sf['test'] 或 sf['test'].head() 也相同

我不明白为什么一种语法显示值“3”,而另一种语法则不显示。 sf[1]['test'] 中的值是 3 还是 0 ?

最佳答案

SFrame 是不可变的,因此它们实际上不支持项目分配。您在这里看到的差异的原因是因为

sf[1]['test']

实际上根本不是指SFrame。 “sf[1]”返回一个字典,其中的键与 SFrame 的列名称匹配,值与 SFrame 的第二行匹配。当您为“sf[1]['test']”分配一个数字时,您正在更改返回的字典中“test”键的值,因此 SFrame“sf”不参与分配。仅引用“test”列的第二个值并分配值“3”的正确方法是:

sf['test'][1] = 3

这将返回此错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-c52dab41d5dd> in <module>()
----> 1 sf['test'][1] = 3

TypeError: 'SArray' object does not support item assignment

关于sframe - 为单个 SFrame 元素分配一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35548668/

相关文章:

pycharm - graphlab.SFrame.show()错误: Requested port is unavailable: None

python - 来自 numpy 数组的 SFrame

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

python - Graphlab sframe - 有什么方法可以转置 sframe 吗?

python - Python中数据的高效拆分

machine-learning - 在 GraphLab Sframe 中过滤和显示值?

Python:对 graphlab.SFrame 的所有行的一行的不同列进行迭代操作

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

python - 使用 sframe.apply() 导致运行时错误