Iterate rows and columns in Spark dataframe

前端 未结 7 1068
囚心锁ツ
囚心锁ツ 2020-12-23 12:32

I have the following Spark dataframe that is created dynamically:

val sf1 = StructField(\"name\", StringType, nullable = true)
val sf2 = StructField(\"sector         


        
7条回答
  •  渐次进展
    2020-12-23 13:01

    You can convert Row to Seq with toSeq. Once turned to Seq you can iterate over it as usual with foreach, map or whatever you need

        sqlDF.foreach { row => 
               row.toSeq.foreach{col => println(col) }
        }
    

    Output:

    Berta
    bbb
    30
    Joe
    Andy
    aaa
    20
    ccc
    40
    

提交回复
热议问题