cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Transpose column to Row

virender_prajap
New Contributor III

Hi, I am not able to do easy transpose. I tried many snaps nut not able to solve this.Transpose
Please help to transpose column into row

6 REPLIES 6

stephenknilans
Contributor

Believe it or not, I had the SAME exact problem. I donโ€™t believe there IS a snap to fix this, BUT, you can use the script snap. That is what I did. AND, though I didnโ€™t write it to be neat. If you tell it you are using a python program, you can pivotdata.py.txt (1.6 KB)
use my script. I was a dreamer, and my dream didnโ€™t work. You might want to change the line:

in_doc[โ€œ_โ€+fieldsr[i]]=fields[i]

to

in_doc[fieldsr[i]]=fields[i]

Thanks Stephen! ๐Ÿ™‚
Iโ€™ll try this approach as well.

tstack
Former Employee

Indeed, thereโ€™s a Pivot snap, but that does the opposite of what youโ€™re looking to do. Until such a snap exists, you can do this using a GroupByN snap and the expression language. If you add a GroupByN snap with a โ€œGroup Sizeโ€ of zero, it will collect all of the incoming data into a single document. You can then follow that up with a Mapper that has this expression:

{}.extend($group.map(x => [x.Category, x.DataType]))

The extend() method will construct a new object containing the key/value pairs returned by the $group.map() call.

Hereโ€™s a screenshot:

04

Hereโ€™s an export of this pipeline:

TransposeExample_2018_08_15.slp (6.8 KB)

Thanks Team!
It is working fine. ๐Ÿ˜„