You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Neal Yin <ne...@workday.com> on 2015/03/31 02:49:46 UTC

data frame API, change groupBy result column name

I ran a line like following:
tb2.groupBy("city", "state").avg("price").show

I got result:
city                 state           AVG(price)
Charlestown          New South Wales 1200.0
Newton           ... MA              1200.0
Coral Gables     ... FL              1200.0
Castricum            Noord-Holland   1200.0
Ornex                Rhone-Alpes     1200.0

How do I change the column name "AVG(price)" to something more readable?

Thanks,

-Neal

Re: data frame API, change groupBy result column name

Posted by Michael Armbrust <mi...@databricks.com>.
You'll need to use the longer form for aggregation:

tb2.groupBy("city", "state").agg(avg("price").as("newName")).show

depending on the language you'll need to import:
scala: import org.apache.spark.sql.functions._
python: from pyspark.sql.functions import *

On Mon, Mar 30, 2015 at 5:49 PM, Neal Yin <ne...@workday.com> wrote:

>  I ran a line like following:
> tb2.groupBy("city", "state").avg("price").show
>
>  I got result:
>  city                 state           AVG(price)
> Charlestown          New South Wales 1200.0
> Newton           ... MA              1200.0
> Coral Gables     ... FL              1200.0
> Castricum            Noord-Holland   1200.0
> Ornex                Rhone-Alpes     1200.0
>
>  How do I change the column name “AVG(price)” to something more readable?
>
>  Thanks,
>
>  -Neal
>