How to get the values in DataFrame with the correct DataType?

前端 未结 2 576
被撕碎了的回忆
被撕碎了的回忆 2021-01-27 05:49

When I tried to get some values in a DataFrame, like:

df.select(\"date\").head().get(0) // type: Any

The result type is Any<

2条回答
  •  日久生厌
    2021-01-27 06:50

    You can call the generic getAs method as getAs[Int](columnIndex), getAs[String](columnIndex) or use specific methods like getInt(columnIndex), getString(columnIndex).

    Link to the Scaladoc for org.apache.spark.sql.Row.

提交回复
热议问题