How to add null values ββto array from scala spark
1 answer
You need to make an array of type Option
, and it null
will be 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|
+--------+
+2
source to share