get min and max from a specific column scala spark dataframe

后端 未结 7 1160
梦谈多话
梦谈多话 2021-02-01 04:37

I would like to access to the min and max of a specific column from my dataframe but I don\'t have the header of the column, just its number, so I should I do using scala ?

7条回答
  •  野性不改
    2021-02-01 04:53

    How about getting the column name from the metadata:

    val selectedColumnName = df.columns(q) //pull the (q + 1)th column from the columns array
    df.agg(min(selectedColumnName), max(selectedColumnName))
    

提交回复
热议问题