I have a dataframe as below now I need to transpose the data output as key-Value pair. Where Key being the ColumnName and Value as the columnsValue.
+---+----+------+-----+
|age| dob|gender| name|
+---+----+------+-----+
| 25|1991| M|Ankit|
+---+----+------+-----+
Required Output
+-------+-------+
|Key |Value |
+-------+-------+
|age |25 |
|dob |1991 |
|gender |M |
|name |Ankit |
+-------+-------+
I tried using the sample code given in the following link https://codereview.stackexchange.com/questions/200391/pyspark-code-that-turns-columns-into-rows
But this gives me an error as below,
cPickle.PicklingError: Could not serialize object: Py4JError: An error occurred while calling o149.__getnewargs__. Trace:
py4j.Py4JException: Method __getnewargs__([]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
at py4j.Gateway.invoke(Gateway.java:274)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)
Any help on this aspect would be really helpful.