我已经在H2OR包中工作了很长一段时间了,但是最近不得不转到Python包。
在大多数情况下,H2OFrame被设计成像pandasDataFrame对象一样工作。然而,有几个障碍我没有克服…在熊猫中,如果我想删除一些行:

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],:]

07-24 09:52