You can use the more verbose syntax:

d.groupBy("_1").agg(d("_1"), sum("_1").as("sum_1"), sum("_2").as("sum_2"))

On Tue, Apr 21, 2015 at 1:06 AM, Justin Yip <[email protected]> wrote:

> Hello,
>
> I would like rename a column after aggregation. In the following code, the
> column name is "SUM(_1#179)", is there a way to rename it to a more
> friendly name?
>
> scala> val d = sqlContext.createDataFrame(Seq((1, 2), (1, 3), (2, 10)))
> scala> d.groupBy("_1").sum().printSchema
> root
>  |-- _1: integer (nullable = false)
>  |-- SUM(_1#179): long (nullable = true)
>  |-- SUM(_2#180): long (nullable = true)
>
> Thanks.
>
> Justin
>
> ------------------------------
> View this message in context: Column renaming after DataFrame.groupBy
> <http://apache-spark-user-list.1001560.n3.nabble.com/Column-renaming-after-DataFrame-groupBy-tp22586.html>
> Sent from the Apache Spark User List mailing list archive
> <http://apache-spark-user-list.1001560.n3.nabble.com/> at Nabble.com.
>

Reply via email to