當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python PySpark DataFrame exceptAll方法用法及代碼示例

PySpark DataFrame 的 exceptAll(~) 方法返回一個新的 DataFrame,該新的 DataFrame 存在於該 DataFrame 中,但不存在於其他 DataFrame 中。

參數

1. other | PySpark DataFrame

另一個PySpark 數據幀。

返回值

PySpark 數據幀。

例子

考慮以下PySpark DataFrame:

df = spark.createDataFrame([["Alex", 20], ["Bob", 30], ["Cathy", 40]], ["name", "age"])
df.show()



+-----+---+
| name|age|
+-----+---+
| Alex| 20|
|  Bob| 30|
|Cathy| 40|
+-----+---+

假設另一個DataFrame是:

df_other = spark.createDataFrame([["Alex", 20], ["Bob", 35], ["Cathy", 40]], ["name", "age"])
df_other.show()



+-----+---+
| name|age|
+-----+---+
| Alex| 20|
|  Bob| 35|
|Cathy| 40|
+-----+---+

獲取 PySpark DataFrame 中不存在於另一個 PySpark DataFrame 中的所有行

要獲取 dfdf_other 中不存在的所有行:

df.exceptAll(df_other).show()



+----+---+
|name|age|
+----+---+
| Bob| 30|
+----+---+

相關用法


注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 PySpark DataFrame | exceptAll method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。