unionByName

これと別の DataFrame の行の和集合を含む新しい DataFrame を返します。

構文

unionByName(other: "DataFrame", allowMissingColumns: bool = False)

パラメーター

パラメーター タイプ 説明
other DataFrame 結合する必要がある別の DataFrame。
allowMissingColumns bool、省略可能、既定の False 不足している列を許可するかどうかを指定します。

返品

DataFrame: 2 つの指定された DataFrame の対応する列を持つ結合された行を含む新しい DataFrame。

メモ

このメソッドは、両方の入力 DataFrame に対して共用体操作を実行し、列を (位置ではなく) 名前で解決します。 allowMissingColumnsが True の場合、不足している列は null で埋められます。

例示

df1 = spark.createDataFrame([[1, 2, 3]], ["col0", "col1", "col2"])
df2 = spark.createDataFrame([[4, 5, 6]], ["col1", "col2", "col0"])
df1.unionByName(df2).show()
# +----+----+----+
# |col0|col1|col2|
# +----+----+----+
# |   1|   2|   3|
# |   6|   4|   5|
# +----+----+----+

df1 = spark.createDataFrame([[1, 2, 3]], ["col0", "col1", "col2"])
df2 = spark.createDataFrame([[4, 5, 6]], ["col1", "col2", "col3"])
df1.unionByName(df2, allowMissingColumns=True).show()
# +----+----+----+----+
# |col0|col1|col2|col3|
# +----+----+----+----+
# |   1|   2|   3|NULL|
# |NULL|   4|   5|   6|
# +----+----+----+----+