How can I convert a column in H2OFrame to python list?

I've read PythonBooklet.pdf from H2O.ai and the python API documentation but still can't find a clean way to do this. I know I can do one of the following:

  • Convert H2OFrame to Spark DataFrame and do flatMap

    + collect

    or collect

    + validation .
  • Use H2O get_frame_data

    which gives me a header and data row separated \n

    ; then convert it to a list (numeric list in my case).

Is there a better way to do this? Thank.

+4


source to share


2 answers


You can try something like this: output the H2OFrame in python as a pandas dataframe by calling .as_data_frame () and then calling .tolist () on the column of interest.

Standalone example w / iris



import h2o
h2o.init()
df = h2o.import_file("iris_wheader.csv")
pd = df.as_data_frame()
pd['sepal_len'].tolist()

      

+5


source


You can (1) convert an H2o frame to a pandas data frame, and (2) convert a pandas data frame to a list like this:



pd=h2o.as_list(h2oFrame) 
l=pd["column"].tolist()

      

0


source







All Articles