-3

suppose the data is T_32_P_1_A_420_H_60_R_0.30841494477846165_S_0 using scala spark dataframe, how to split into the following format

T 32
P 1
A 420
H 60
R 0.30841494477846165
S 0

Any suggestions are greatly appreciated.

Thanks in advance

Shakti
  • 5
  • 1
  • 3

1 Answers1

0

another example

+-------+-------------+-----------------------------------------------------------------------------+
|Pcode  |Pname        |Pdetails                                                                     |
+-------+-------------+-----------------------------------------------------------------------------+
|Water12|HimalayaWater|Price,1.20;Qty,250ml;Brand,Himalaya;Class,Liquid                             |
|Snack23|Mad Pringles |Price,0.65;Qty,165 g;Brand,MadLtd;Class,Snacks;Batch,12312334;Exp,12/Feb/2012|
+-------+-------------+-----------------------------------------------------------------------------+

i want pdeatils to be split into two columns Type and Value, and expected output is

+-------+-------------+-----+-----------+
|Pcode  |Pname        |Type |Value      |
+-------+-------------+-----+-----------+
|Water12|HimalayaWater|Price|1.20       |
|Water12|HimalayaWater|Qty  |250ml      |
|Water12|HimalayaWater|Brand|Himalaya   |
|Water12|HimalayaWater|Class|Liquid     |
|Snack23|Mad Pringles |Price|0.65       |
|Snack23|Mad Pringles |Qty  |165 g      |
|Snack23|Mad Pringles |Brand|MadLtd     |
|Snack23|Mad Pringles |Class|Snacks     |
|Snack23|Mad Pringles |Batch|12312334   |
|Snack23|Mad Pringles |Exp  |12/Feb/2012|
+-------+-------------+-----+-----------+
Shakti
  • 5
  • 1
  • 3