我想把两个Dataframe放在一个Dataframe中,所以每个Dataframe都是子列,不是Dataframe的连接。所以我有两个Dataframe,stat1,df和stat2,df,它们看起来像这样:
root
|-- max_scenes: integer (nullable = true)
|-- median_scenes: double (nullable = false)
|-- avg_scenes: double (nullable = true)
+----------+-------------+------------------+
|max_scenes|median_scenes|avg_scenes |
+----------+-------------+------------------+
|97 |7.0 |10.806451612903226|
|97 |7.0 |10.806451612903226|
|97 |7.0 |10.806451612903226|
|97 |7.0 |10.806451612903226|
+----------+-------------+------------------+
root
|-- max: double (nullable = true)
|-- type: string (nullable = true)
+-----+-----------+
|max |type |
+-----+-----------+
|10.0 |small |
|25.0 |medium |
|50.0 |large |
|250.0|extra_large|
+-----+-----------+
,我希望结果是:
root
|-- some_statistics1: struct (nullable = true)
| |-- max_scenes: integer (nullable = true)
|-- median_scenes: double (nullable = false)
|-- avg_scenes: double (nullable = true)
|-- some_statistics2: struct (nullable = true)
| |-- max: double (nullable = true)
|-- type: string (nullable = true)
有没有办法把这两个放在图中?stat1_df和stat2_df是简单的Dataframe,没有数组和嵌套列。最后的Dataframe被写入mongodb。如果有任何其他问题我在这里回答。
1条答案
按热度按时间cidc1ykv1#
检查以下代码。
添加
id
列中的两个DataFrame
,将所有列移到结构中,然后使用join
两个Dataframe