我在PySparkavg_length_df
中有一个Spark数据帧,看起来像-
+----------------+---------+----------+-----------+---------+-------------+----------+
| id | x| a| b| c| country| param|
+----------------+---------+----------+-----------+---------+-------------+----------+
| 40.0| 9.0| 5.284| 5.047| 6.405| 13.0|avg_length|
+----------------+---------+----------+-----------+---------+-------------+----------+
我想把它从一行移到另一列,这样它就变成了-
+----------+
|avg_length|
+----------+
| 40.0|
| 9.0|
| 5.284|
| 5.047|
| 6.405|
| 13.0|
+----------+
接下来,我有第二个数据帧df2
:
+----------------+------+
| col_names|dtypes|
+----------------+------+
| id|string|
| x| int|
| a|string|
| b|string|
| c|string|
| country|string|
+----------------+------+
我想在df2
中创建一列avg_length
,等于上面的转置数据帧。因此,预期输出如下所示:
+----------------+------+----------+
| 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|
+----------------+------+----------+
如何完成这两个操作?你知道吗
下面是在pyspark中转置数据帧(RDD)的代码。你知道吗
在转置之后,您可以简单地合并两个数据帧。 我希望这有帮助。你知道吗
相关问题 更多 >
编程相关推荐