You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Darshan Pandya <da...@gmail.com> on 2017/02/01 20:02:51 UTC

pivot over non numerical data

Hello,

I am trying to transpose some data using groupBy pivot aggr as mentioned in
this blog
https://databricks.com/blog/2016/02/09/reshaping-data-with-pivot-in-apache-spark.html

But this works only for numerical data.
Any hints for doing the same thing for non numerical data ?


-- 
Sincerely,
Darshan

Re: pivot over non numerical data

Posted by Darshan Pandya <da...@gmail.com>.
Thanks Kevin,
Worked like a charm.
FYI for readers,
val temp1 =
temp.groupBy("reference_id").pivot("char_name").agg(max($"char_value"))

I didn't know I can use 'agg' with a string max. I was using it incorrectly
as below
temp.groupBy("reference_id").pivot("char_name").max("char_value")

On Wed, Feb 1, 2017 at 11:56 PM, Kevin Mellott <ke...@gmail.com>
wrote:

> This should work for non-numerical data as well - can you please elaborate
> on the error you are getting and provide a code sample? As a preliminary
> hint, you can "aggregate" text values using *max*.
>
> df.groupBy("someCol")
>   .pivot("anotherCol")
>   .agg(max($"textCol"))
>
> Thanks,
> Kevin
>
> On Wed, Feb 1, 2017 at 2:02 PM, Darshan Pandya <da...@gmail.com>
> wrote:
>
>> Hello,
>>
>> I am trying to transpose some data using groupBy pivot aggr as mentioned
>> in this blog
>> https://databricks.com/blog/2016/02/09/reshaping-data-with-
>> pivot-in-apache-spark.html
>>
>> But this works only for numerical data.
>> Any hints for doing the same thing for non numerical data ?
>>
>>
>> --
>> Sincerely,
>> Darshan
>>
>>
>


-- 
Sincerely,
Darshan

Re: pivot over non numerical data

Posted by Kevin Mellott <ke...@gmail.com>.
This should work for non-numerical data as well - can you please elaborate
on the error you are getting and provide a code sample? As a preliminary
hint, you can "aggregate" text values using *max*.

df.groupBy("someCol")
  .pivot("anotherCol")
  .agg(max($"textCol"))

Thanks,
Kevin

On Wed, Feb 1, 2017 at 2:02 PM, Darshan Pandya <da...@gmail.com>
wrote:

> Hello,
>
> I am trying to transpose some data using groupBy pivot aggr as mentioned
> in this blog
> https://databricks.com/blog/2016/02/09/reshaping-data-
> with-pivot-in-apache-spark.html
>
> But this works only for numerical data.
> Any hints for doing the same thing for non numerical data ?
>
>
> --
> Sincerely,
> Darshan
>
>