intersectar

Devolva um novo DataFrame contendo apenas linhas tanto neste DataFrame como noutro DataFrame. Note que quaisquer duplicados são removidos. Para preservar duplicados, use intersectAll.

Sintaxe

intersect(other: "DataFrame")

Parâmetros

Parâmetro Tipo Descrição
other DataFrame Outro DataFrame que precisa de ser combinado.

Devoluções

DataFrame: DataFrame Combinado.

Notes

Isto é equivalente ao INTERSECT SQL.

Exemplos

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.intersect(df2).sort("C1", "C2")
result_df.show()
# +---+---+
# | C1| C2|
# +---+---+
# |  a|  1|
# |  b|  3|
# +---+---+

df1 = spark.createDataFrame([(1, "A"), (2, "B")], ["id", "value"])
df2 = spark.createDataFrame([(2, "B"), (3, "C")], ["id", "value"])
result_df = df1.intersect(df2).sort("id", "value")
result_df.show()
# +---+-----+
# | id|value|
# +---+-----+
# |  2|    B|
# +---+-----+