从特定列Scala Spark数据帧中获取最小值和最大值 [英] get min and max from a specific column scala spark dataframe

查看:422
本文介绍了从特定列Scala Spark数据帧中获取最小值和最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数据框中访问特定列的最小值和最大值,但是我没有列的标题,只有列号,所以我应该使用scala吗?

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 ?

也许是这样的:

val q = nextInt(ncol) //we pick a random value for a column number
col = df(q)
val minimum = col.min()

很抱歉,这听起来像是一个愚蠢的问题,但我找不到有关此问题的信息:/

Sorry if this sounds like a silly question but I couldn't find any info on SO about this question :/

推荐答案

如何从元数据中获取列名:

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))

这篇关于从特定列Scala Spark数据帧中获取最小值和最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆