get specific row from spark dataframe

前端 未结 9 1720
闹比i
闹比i 2020-12-17 07:58

Is there any alternative for df[100, c(\"column\")] in scala spark data frames. I want to select specific row from a column of spark data frame. for example

9条回答
  •  别那么骄傲
    2020-12-17 08:28

    There is a scala way (if you have a enough memory on working machine):

    val arr = df.select("column").rdd.collect
    println(arr(100))
    

    If dataframe schema is unknown, and you know actual type of "column" field (for example double), than you can get arr as following:

    val arr = df.select($"column".cast("Double")).as[Double].rdd.collect
    

提交回复
热议问题