I have a Spark DataFrame in PySpark avg_length_df that looks like -
+----------------+---------+----------+-----------+---------+-------------+----------+
| id | x| a| b| c| country| param|
+----------------+---------+----------+-----------+---------+-------------+----------+
| 40.0| 9.0| 5.284| 5.047| 6.405| 13.0|avg_length|
+----------------+---------+----------+-----------+---------+-------------+----------+
I want to transpose it from row to column so that it becomes -
+----------+
|avg_length|
+----------+
| 40.0|
| 9.0|
| 5.284|
| 5.047|
| 6.405|
| 13.0|
+----------+
Next, I have a second DataFrame df2:
+----------------+------+
| col_names|dtypes|
+----------------+------+
| id|string|
| x| int|
| a|string|
| b|string|
| c|string|
| country|string|
+----------------+------+
I want to create a column avg_length in df2 the equals to the transposed DataFrame above. So the expected output would look like:
+----------------+------+----------+
| col_names|dtypes|avg_length|
+----------------+------+----------+
| id|string| 40.0|
| x| int| 9.0|
| a|string| 5.284|
| b|string| 5.047|
| c|string| 6.405|
| country|string| 13.0|
+----------------+------+----------+
How do I complete the 2 operations?