How do I convert an RDD with a SparseVector Column to a DataFrame with a column as Vector

前端 未结 3 1436
别跟我提以往
别跟我提以往 2020-12-28 19:55

I have an RDD with a tuple of values (String, SparseVector) and I want to create a DataFrame using the RDD. To get a (labe

3条回答
  •  清酒与你
    2020-12-28 20:23

    this is an example in scala for spark 2.1

    import org.apache.spark.ml.linalg.Vector
    
    def featuresRDD2DataFrame(features: RDD[Vector]): DataFrame = {
        import sparkSession.implicits._
        val rdd: RDD[(Double, Vector)] = features.map(x => (0.0, x))
        val df = rdd.toDF("label","features").select("features")
        df
      }
    

    the toDF() was not recognized by the compiler on the features rdd

提交回复
热议问题