[英]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.