Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Return a new DataFrame containing rows in this DataFrame but not in another DataFrame.
Syntax
subtract(other: "DataFrame")
Parameters
| Parameter | Type | Description |
|---|---|---|
other |
DataFrame | Another DataFrame that needs to be subtracted. |
Returns
DataFrame: Subtracted DataFrame.
Notes
This is equivalent to EXCEPT DISTINCT in SQL.
Examples
df1 = spark.createDataFrame([("a", 1), ("a", 1), ("b", 3), ("c", 4)], ["C1", "C2"])
df2 = spark.createDataFrame([("a", 1), ("a", 1), ("b", 3)], ["C1", "C2"])
result_df = df1.subtract(df2)
result_df.show()
# +---+---+
# | C1| C2|
# +---+---+
# | c| 4|
# +---+---+
df1 = spark.createDataFrame([(1, "A"), (2, "B")], ["id", "value"])
df2 = spark.createDataFrame([(2, "B"), (3, "C")], ["id", "value"])
result_df = df1.subtract(df2)
result_df.show()
# +---+-----+
# | id|value|
# +---+-----+
# | 1| A|
# +---+-----+