How to explode space-separated column?

后端 未结 1 1617
遇见更好的自我
遇见更好的自我 2021-01-16 17:56

I have a sample dataframe in Spark Scala which contains one column and many other columns 50+ and need to explode id :

example data:

id             n         


        
1条回答
  •  心在旅途
    2021-01-16 18:31

    Try this:

    import org.apache.spark.sql.functions._
    
    scala> df.withColumn("id", explode(split($"id", " "))).show
    +---+----+-------+
    | id|name|address|
    +---+----+-------+
    |234| auh|    aus|
    |435| auh|    aus|
    |567| auh|    aus|
    |345|muji|     uk|
    |123|muji|     uk|
    +---+----+-------+
    

    0 讨论(0)
提交回复
热议问题