How to explode columns?

后端 未结 4 882
無奈伤痛
無奈伤痛 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:31

    Just to give the Pyspark version of sgvd's answer. If the array column is in Col2, then this select statement will move the first nElements of each array in Col2 to their own columns:

    from pyspark.sql import functions as F            
    df.select([F.col('Col2').getItem(i) for i in range(nElements)])
    

提交回复
热议问题