distinct

この DataFrame 内の個別の行を含む新しい DataFrame を返します。

構文

distinct()

返品

DataFrame: 個別のレコードを含む DataFrame。

例示

df = spark.createDataFrame(
    [(14, "Tom"), (23, "Alice"), (23, "Alice")], ["age", "name"])
df.distinct().show()
# +---+-----+
# |age| name|
# +---+-----+
# | 14|  Tom|
# | 23|Alice|
# +---+-----+

df.distinct().count()
# 2

df = spark.createDataFrame(
    [(14, "Tom", "M"), (23, "Alice", "F"), (23, "Alice", "F"), (14, "Tom", "M")],
    ["age", "name", "gender"])
df.distinct().show()
# +---+-----+------+
# |age| name|gender|
# +---+-----+------+
# | 14|  Tom|     M|
# | 23|Alice|     F|
# +---+-----+------+