Let's take the below dataframe as an example
+--------+-----------------------------
|id | fee_amount | discount_amount |
|1 | 10.00 | 5.0 |
|2 | 20.0 | 3.0 |
I want to be able to convert the above dataframe to following
+--------+-----------------------------
|id | amount_type | discount_amount |
|1 | fee | 10.0 |
|1 | discount | 5.0 |
|2 | fee | 20.0 |
|2 | discount | 3.0 |
I just double the number of rows and I'm ok with that.
I only want one column where amount value is stored and another column where a type of amount is stored. In the above example, I am given names of columns i.e. fee_amount
, discount_amount
that needs to be transposed. Is this even possible to do in spark dataframe?