如何在 H2OFrame 中删除行?
How to drop rows in an H2OFrame?
我已经在 h2o R 包中工作了一段时间,现在,但最近不得不转向 python 包。
在大多数情况下,H2OFrame
被设计为像 pandas DataFrame
对象一样工作。但是,有几个障碍我还没有克服......在 Pandas 中,如果我想删除一些行:
df.drop([0,1,2], axis=0, inplace=True)
但是,我不知道如何使用 H2OFrame
:
frame.drop([0,1,2], axis=0)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-30-0eff75c48e35> in <module>()
----> frame.drop([0,1,2], axis=0)
TypeError: drop() got an unexpected keyword argument 'axis'
他们的 github 源文档表明 drop 方法仅适用于列,因此显然明显的方法不起作用:
def drop(self, i):
"""Drop a column from the current H2OFrame.
有没有办法从 H2OFrame
中删除行?
目前,H2OFrame.drop
方法不支持此功能,但我们添加了一个 ticket 来添加对删除多行(和多列)的支持。
同时,您可以按索引对行进行子集化:
import h2o
h2o.init(nthreads = -1)
hf = h2o.H2OFrame([[1,3],[4,5],[3,0],[5,5]]) # 4 rows x 2 columns
hf2 = hf[[1,3],:] # Keep some of the rows by passing an index
请注意,索引列表 [1,3]
是有序的。如果您尝试传递 [3,1]
,则会出现错误。 H2O 不会对行重新排序,这是它告诉你的方式。如果您有乱序索引列表,只需先将 sorted
函数包裹起来即可。
hf2 = hf[sorted([3,3]),:]
最后,如果您愿意,也可以将新的子集框架重新分配给原始框架名称,如下所示:
hf = hf[[1,3],:]
由于现在支持此功能,因此我想突出显示说明如何按索引删除的评论:
df = df.drop([0,1,2], axis=0)
如果 axis = 1(默认),则删除列;如果 axis=0 则删除行。
drop(index, axis=1)
其中索引是要删除的列索引、列名或行索引的列表;或按名称删除单个列的字符串;或按索引删除单个列的 int。
我已经在 h2o R 包中工作了一段时间,现在,但最近不得不转向 python 包。
在大多数情况下,H2OFrame
被设计为像 pandas DataFrame
对象一样工作。但是,有几个障碍我还没有克服......在 Pandas 中,如果我想删除一些行:
df.drop([0,1,2], axis=0, inplace=True)
但是,我不知道如何使用 H2OFrame
:
frame.drop([0,1,2], axis=0)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-30-0eff75c48e35> in <module>()
----> frame.drop([0,1,2], axis=0)
TypeError: drop() got an unexpected keyword argument 'axis'
他们的 github 源文档表明 drop 方法仅适用于列,因此显然明显的方法不起作用:
def drop(self, i):
"""Drop a column from the current H2OFrame.
有没有办法从 H2OFrame
中删除行?
目前,H2OFrame.drop
方法不支持此功能,但我们添加了一个 ticket 来添加对删除多行(和多列)的支持。
同时,您可以按索引对行进行子集化:
import h2o
h2o.init(nthreads = -1)
hf = h2o.H2OFrame([[1,3],[4,5],[3,0],[5,5]]) # 4 rows x 2 columns
hf2 = hf[[1,3],:] # Keep some of the rows by passing an index
请注意,索引列表 [1,3]
是有序的。如果您尝试传递 [3,1]
,则会出现错误。 H2O 不会对行重新排序,这是它告诉你的方式。如果您有乱序索引列表,只需先将 sorted
函数包裹起来即可。
hf2 = hf[sorted([3,3]),:]
最后,如果您愿意,也可以将新的子集框架重新分配给原始框架名称,如下所示:
hf = hf[[1,3],:]
由于现在支持此功能,因此我想突出显示说明如何按索引删除的评论:
df = df.drop([0,1,2], axis=0)
如果 axis = 1(默认),则删除列;如果 axis=0 则删除行。
drop(index, axis=1)
其中索引是要删除的列索引、列名或行索引的列表;或按名称删除单个列的字符串;或按索引删除单个列的 int。