【问题标题】:Joining two h2o dataframes加入两个 h2o 数据框
【发布时间】:2019-06-18 16:41:53
【问题描述】:

我有两个 h2o 框架,我想加入它们,因为两者都存在一个相同的列,我正在使用 Java API 并从 spark 数据帧中获取 h2o 框架。

    H2OFrame trainDataFrame = h2oContext.asH2OFrame(train_validation); 
    H2OFrame validationDataFrame = h2oContext.asH2OFrame(train_validation);
    H2OFrame testDataFrame = h2oContext.asH2OFrame(testSparkDataFrame); 

我可以使用 spark 数据帧来连接数据,因为我的数据非常大,并且 RDD 可以在这里工作,所以我需要将 h2o 帧作为内存对象使用。

【问题讨论】:

    标签: h2o


    【解决方案1】:

    查看h2o.merge() 命令。

    # Currently, this function only supports `all.x = TRUE`. All other permutations will fail.
    library(h2o)
    h2o.init()
    
    # Create two simple, two-column R data frames by inputting values, ensuring that both have a common column (in this case, "fruit").
    left <- data.frame(fruit = c('apple','orange','banana','lemon','strawberry','blueberry'),
                       color = c('red','orange','yellow','yellow','red','blue'))
    right <- data.frame(fruit = c('apple','orange','banana','lemon','strawberry','watermelon'),
                        citrus = c(FALSE, TRUE, FALSE, TRUE, FALSE, FALSE))
    
    # Create the H2O data frames from the inputted data.
    l.hex <- as.h2o(left)
    print(l.hex)
            fruit  color
     1      apple    red
     2     orange orange
     3     banana yellow
     4      lemon yellow
     5 strawberry    red
     6  blueberry   blue
    
    [6 rows x 2 columns]
    
    r.hex <- as.h2o(right)
    print(r.hex)
            fruit citrus
     1      apple  FALSE
     2     orange   TRUE
     3     banana  FALSE
     4      lemon   TRUE
     5 strawberry  FALSE
     6 watermelon  FALSE
    
    [6 rows x 2 columns]
    
    # Merge the data frames. The result is a single dataset with three columns.
    left.hex <- h2o.merge(l.hex, r.hex, all.x = TRUE)
    print(left.hex)
           fruit  color citrus
    1  blueberry   blue   <NA>
    2      apple    red  FALSE
    3     banana yellow  FALSE
    4      lemon yellow   TRUE
    5     orange orange   TRUE
    6 strawberry    red  FALSE
    
    [6 rows x 3 columns]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 2018-06-11
      • 1970-01-01
      相关资源
      最近更新 更多