我可以在if()中使用IsNull或na来检查缺失值吗?

时间:2015-10-28 21:25:02

标签: scala h2o

这个不重复我有新问题。我试着写这个

package org.apache.spark.h2o.utils

import water.fvec.{NewChunk, Frame, Chunk}
import water._

class Miss extends MRTask {
  override def map(c: Chunk, nc: NewChunk): Unit = {
    for (row <- 0 until c.len()) {
      if(c.atd(row) == 0){  
       nc.addNum(0)
      }
      else
       nc.addNum(1)
    }
  }
}

我可以在if (...)中使用na或IsNull来检查row是否为空吗?

代码结果

          A    B    C    D            E    NaN
    min                                     0
   mean                                     0
 stddev                                     0
    max                                     1
missing                                     0
      0  5.1  3.5  1.4  0.2  Iris-setosa    1
      1  4.9    3  1.4  0.2  Iris-setosa    1
      2  4.7  3.2  1.3  0.2  Iris-setosa    1
      3  4.6  3.1  1.5  0.2  Iris-setosa    1
      4    5  3.6  1.4  0.2  Iris-setosa    1
      5  5.4  3.9  1.7  0.4  Iris-setosa    1
      6  4.6  3.4  1.4  0.3  Iris-setosa    1
      7    5  3.4  1.5  0.2  Iris-setosa    1
      8  4.4  2.9  1.4  0.2  Iris-setosa    1
      9  4.9  3.1  1.5  0.1  Iris-setos...

1 个答案:

答案 0 :(得分:1)

类似的东西:

c.atd(row) match {
  case nan: Double if nan.isNaN => nc.addNum(0)
  case 0 => nc.addNum(0)
  case _ => nc.addNum(1)
}