Skip to main content

Download data

Sometimes you need to download data from the H2O-3 Secure cluster. For example, when computing model predictions, it might be desirable to save these predictions for later.

Download to local memory​

H2O-3 Secure has functions like as_data_frame and get_frame_data in Python and as.data.frame in R that let you download the data directly into the client program memory.

note

For large datasets this might not be practical because the whole frame is downloaded as CSV into the client program memory.

import h2o
h2o.init()
iris_hex = h2o.import_file("http://h2o-public-test-data.s3.amazonaws.com/smalldata/iris/iris_wheader.csv")
iris_csv_string = iris_hex.get_frame_data()
iris_pd = iris_hex.as_data_frame(use_pandas=True)

Save to a file system​

The export file function can be used to save the data to an arbitrary location. The location has to be one that the server has access to, so either the server filesystem or a distributed filesystem like HDFS or S3. This function can save the data in either CSV format (default) or Parquet format.

import h2o
h2o.init()
iris_hex = h2o.import_file("http://h2o-public-test-data.s3.amazonaws.com/smalldata/iris/iris_wheader.csv")
h2o.export_file(iris_hex, path = "/tmp/pred.csv", force = True)

# To save as a parquet:
path = "file:///tmp/iris.parquet"
h2o.export_file(iris_hex, path, format="parquet")

Feedback