You are viewing documentation about an older version (1.12.1). View latest version

snowflake.snowpark.DataFrame.union_by_name

DataFrame.union_by_name(other: DataFrame) DataFrame[source]

Returns a new DataFrame that contains all the rows in the current DataFrame and another DataFrame (other), excluding any duplicate rows.

This method matches the columns in the two DataFrames by their names, not by their positions. The columns in the other DataFrame are rearranged to match the order of columns in the current DataFrame.

Example:

>>> df1 = session.create_dataframe([[1, 2]], schema=["a", "b"])
>>> df2 = session.create_dataframe([[2, 1]], schema=["b", "a"])
>>> df1.union_by_name(df2).show()
-------------
|"A"  |"B"  |
-------------
|1    |2    |
-------------
Copy
Parameters:

other – the other DataFrame that contains the rows to include.