问题
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