![](/img/trans.png)
[英]Spark Scala: How to replace null with values from an array or another dataframe
[英]How to add null values in an array in spark scala
val data = Array(-999.9,-0.5, -0.3, 0.0, 0.2, 999.9)
val dataFrame = sqlContext.createDataFrame(data.map(Tuple1.apply)).toDF("features")
我想在上面的数组中引入null条目。 我在下面试过但是没用。
val data = Array(-999.9,-0.5, -0.3, 0.0, 0.2, 999.9, null)
您需要创建Option
类型的数组, null
将为None:
val data = Array(Some(-999.9),Some(-0.5), Some(-0.3), Some(0.0), Some(0.2), Some(999.9),None)
// data: Array[Option[Double]] = Array(Some(-999.9), Some(-0.5), Some(-0.3), Some(0.0), Some(0.2), Some(999.9), None)
val dataFrame = spark.createDataFrame(data.map(Tuple1.apply)).toDF("features")
// dataFrame: org.apache.spark.sql.DataFrame = [features: double]
dataFrame.show
+--------+
|features|
+--------+
| -999.9|
| -0.5|
| -0.3|
| 0.0|
| 0.2|
| 999.9|
| null|
+--------+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.