subset h2o frame in python

前提是你 提交于 2020-01-13 05:32:07

问题


how can I subset a h2o frame in python. if x is a df & Origin is a variable then in pandas we generally can do subsetting by

x[x.Origin == 'AAF']

but with h2o frame it gives the following error: "H2OResponseError: Server error java.lang.IllegalArgumentException: Error: Name lookup of 'x.hex' failed"


回答1:


There are a number of different ways to slice an H2OFrame, row-wise. The methods are outlined in the H2O User Guide section on Slicing Rows.

Here is an Python example of subsetting an H2OFrame based on a column being set to a particular value using the Iris dataset:

import h2o
h2o.init()

# Load data
path = "http://h2o-public-test-data.s3.amazonaws.com/smalldata/iris/iris_wheader.csv"
df = h2o.import_file(path=path)

# Subset data
mask = df["class"] == "Iris-setosa"
newdf = df[mask, :]

# equivalent to both of these, which also work
# newdf = df[df["class"] == "Iris-setosa", :]
# newdf = df[df["class"] == "Iris-setosa"]

The newdf = df[df["class"] == "Iris-setosa"] version is almost identical to the format you have above, except H2OFrames do not support referencing a column like this: df.class; you must use: df["class"].



来源:https://stackoverflow.com/questions/45832671/subset-h2o-frame-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!