合并具有嵌套不同架构的两个数据框

时间:2018-11-27 01:42:10

标签: apache-spark pyspark

Dataframe1看起来像这样

android {
    ...
    packagingOptions{
        doNotStrip '*/mips/*.so'
        doNotStrip '*/mips64/*.so'
    }
    ...
}

数据框2如下所示:

root
 |-- source: string (nullable = true)
 |-- results: array (nullable = true)
 |    |-- content: struct (containsNull = true)
 |    |    |-- ptype: string (nullable = true)
 |    |    |-- domain: string (nullable = true)
 |    |    |-- verb: string (nullable = true)
 |    |    |-- foobar: map (nullable = true)
 |    |    |    |-- key: string
 |    |    |    |-- value: string (valueContainsNull = true)
 |    |    |-- fooId: integer (nullable = true)
 |-- date: string (nullable = false)
 |-- hour: string (nullable = false)

请注意差异-第二个数据帧中没有root |-- source: string (nullable = true) |-- results: array (nullable = true) | |-- content: struct (containsNull = true) | | |-- ptype: string (nullable = true) | | |-- domain: string (nullable = true) | | |-- verb: string (nullable = true) | | |-- foobar: map (nullable = true) | | | |-- key: string | | | |-- value: string (valueContainsNull = true) |-- date: string (nullable = false) |-- hour: string (nullable = false) 。 如何将这两个数据框合并在一起? 我了解这两个架构需要相同才能合并。添加fooId或删除fooId的最佳方法是什么?(由于架构的结构,这是不平凡的)建议进行这种联合的方法是什么。 谢谢

1 个答案:

答案 0 :(得分:0)

考虑了两个数据框让DF1和DF2进入,您可以删除DF1中的多余列,并同时运行两个数据框

// this is to remove the extra column in the dataframe
DF1.drop("fooId")

现在两个DF的列数相同,因此您可以进行联合

DF1.union(DF2)
相关问题