1

how to convert columns to rows and from rows to columns similar to transpose of matrix for the data present in the file.

for ex:- input file:-

    aa ab ac ad ae af ag
    ba bb bc bd be bf bg
    ca cb cc cd ce cf cg

output file:-

   aa ba ca
   ab bb cb
   ac bc cc
   ad bd cd
   ae be ce
   af bf cf
   ag bg cg

Thank you :)

ankush reddy
  • 481
  • 1
  • 5
  • 28

1 Answers1

0

Similar to the question here: How to transpose an RDD in Spark

You can convert the DataFrame back to an rdd by calling df.rdd and follow the same steps provided in the post about RDDs. If the DataFrame is small enough, his first example of a simple transform using collect() would work.

Community
  • 1
  • 1
MrChristine
  • 1,461
  • 13
  • 13
  • Thanks for the reply @MrChristine but if we are having a file we don't the values present the file. so we cannot use seq(for all the values in the file). correct me if am wrong. – ankush reddy Mar 15 '16 at 04:23
  • @AnkushReddySugureddy How is it a problem in this scenario? – zero323 Mar 15 '16 at 12:00
  • @AnkushReddySugureddy I don't follow your statement. The example using Seq() is used to generate a test dataset in the post. You should be able to follow the same workflow. – MrChristine Mar 17 '16 at 01:24