gpt4 book ai didi

H2O Frame 在 python 中的每一行应用函数

转载 作者:行者123 更新时间:2023-12-02 07:50:46 24 4
gpt4 key购买 nike

我正在寻找一种类似于 pandas 中的“apply”功能的方法。我试过了

my_H2Oframe.apply(lambda x: my_function(x), axis=1)

但这行不通。

ValueError: Unimplemented: op < my_function > not bound in H2OFrame

我找到了this question 。看来我们只能使用H2O已经定义的那些函数了。我想一定有一个类似于apply函数的方法,因为这是一个常见的操作。有没有人有解决办法?

最佳答案

目前没有其他应用类型方法。 H2O apply 方法应该与 pandas apply 非常相似。确实,H2O 的 apply 函数仅限于某些运算,例如加法 (+)、减法 (-)、除法等。如果您使用 H2O 没有的运算,则会出现上述错误。

这里有一些示例来尝试了解 apply 函数如何工作(第一个示例获取跨列的平均值,第二个示例返回 bool 列):

h2oframe = h2o.import_file("http://h2o-public-test-data.s3.amazonaws.com/smalldata/prostate/prostate.csv")

h2oframe.apply(lambda x: x.mean(), axis=0)

h2oframe.apply(lambda x: x['PSA'] > x['VOL'],axis=1)

这是当前的文档:

apply(fun=None, axis=0):
Apply a lambda expression to an H2OFrame.

Parameters:
fun – a lambda expression to be applied per row or per column.
axis – 0 = apply to each column; 1 = apply to each row
Returns:
a new H2OFrame with the results of applying fun to the current frame.

关于H2O Frame 在 python 中的每一行应用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48103924/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com