var exprs = dfx.columns.map(max(_))
var df2 = df1.groupBy("x","y","z").agg(exprs.head, exprs.tail: _*)
df2.printSchema()
此输出会创建一个数据框
root
|-- x: string (nullable = true)
|-- y: string (nullable = true)
|-- z: double (nullable = true)
|-- max(a): double (nullable = true)
|-- max(b): double (nullable = true)
|-- max(c): double (nullable = true)
如何以编程方式删除max()并将列重命名为“a”而不是max(a)
答案 0 :(得分:2)
替换
var exprs = dfx.columns.map(max(_))
with(是的,var
工作正常时不要使用val
:
val exprs = dfx.columns.map(c => max(c).alias(c))