How to explode columns?

后端 未结 4 906
無奈伤痛
無奈伤痛 2020-12-25 14:42

After:

val df = Seq((1, Vector(2, 3, 4)), (1, Vector(2, 3, 4))).toDF(\"Col1\", \"Col2\")

I have this DataFrame in Apache Spark:

         


        
4条回答
  •  不思量自难忘°
    2020-12-25 15:16

    Just add on to sgvd's solution:

    If the size is not always the same, you can set nElements like this:

    val nElements = df.select(size('Col2).as("Col2_count"))
                      .select(max("Col2_count"))
                      .first.getInt(0)
    

提交回复
热议问题