unionByName

이 데이터 프레임과 다른 DataFrame의 행 조합이 포함된 새 DataFrame을 반환합니다.

문법

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

매개 변수

매개 변수 유형 설명
other DataFrame 결합해야 하는 또 다른 데이터 프레임입니다.
allowMissingColumns bool, 선택 사항, 기본 False 누락된 열을 허용할지 여부를 지정합니다.

Returns

DataFrame: 지정된 두 DataFrame의 해당 열이 있는 결합된 행을 포함하는 새 DataFrame입니다.

Notes

이 메서드는 두 입력 DataFrames 모두에서 통합 작업을 수행하여 위치가 아닌 이름으로 열을 확인합니다. True이면 allowMissingColumns 누락된 열이 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|
# +----+----+----+----+