Pular para o conteúdo principal

subtrair

Retorna um novo DataFrame contendo as linhas presentes neste DataFrame, mas não em outro DataFrame.

Sintaxe

subtract(other: "DataFrame")

Parâmetros

Parâmetro

Tipo

Descrição

other

DataFrame

Outro DataFrame que precisa ser subtraído.

Devoluções

DataFrame: DataFrame subtraído.

Notas

Isso é equivalente a EXCEPT DISTINCT em SQL.

Exemplos

Python
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|
# +---+-----+