#DataframeMethod
unionByName is a method in Apache Spark that is used to perform a union of two DataFrames by matching columns by their names instead of their positions. This is particularly useful when the schemas of the DataFrames being combined have the same column names but are in a different order, or if some columns are missing in one DataFrame but not in the other.
Syntax: -
DataFrame.unionByName(other, allowMissingColumns=False)
- Type Safety: Both DataFrames must have compatible types for matching columns; otherwise, an error is raised.
- Null Filling: When
allowMissingColumns=True, missing columns in one DataFrame are filled withnull.