You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zhengruifeng (via GitHub)" <gi...@apache.org> on 2023/07/27 04:53:09 UTC
[GitHub] [spark] zhengruifeng commented on a diff in pull request #42151: [SPARK-44565][PYTHON][DOCS] Refine the docs for `Union`, `UnionAll` and `unionByName`
zhengruifeng commented on code in PR #42151:
URL: https://github.com/apache/spark/pull/42151#discussion_r1275730095
##########
python/pyspark/sql/dataframe.py:
##########
@@ -3867,6 +3885,28 @@ def unionByName(self, other: "DataFrame", allowMissingColumns: bool = False) ->
| 1| 2| 3|NULL|
|NULL| 4| 5| 6|
+----+----+----+----+
+
+ Example 3: Union of two DataFrames with few common columns.
+ >>> df1 = spark.createDataFrame([[1, 2, 3]], ["col0", "col1", "col2"])
+ >>> df2 = spark.createDataFrame([[4, 5, 6, 7]], ["col1", "col2", "col3","col4"])
+ >>> df1.unionByName(df2, allowMissingColumns=True).show()
+ +----+----+----+----+----+
+ |col0|col1|col2|col3|col4|
+ +----+----+----+----+----+
+ | 1| 2| 3|NULL|NULL|
+ |NULL| 4| 5| 6| 7|
+ +----+----+----+----+----+
+
+ Example 4: Union of two DataFrames with completely different columns.
+ >>> df1 = spark.createDataFrame([[0, 1, 2]], ["col0", "col1", "col2"])
Review Comment:
this example is good
I manually rename the column names from `a/b/c` to `col0/col1/col2` to be more consistent with other examples
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org