Skip to main content

count (GroupedData)

Counts the number of records for each group.

Syntax

count()

Returns

DataFrame

Examples

Python
df = spark.createDataFrame(
[(2, "Alice"), (3, "Alice"), (5, "Bob"), (10, "Bob")], ["age", "name"])

df.groupBy(df.name).count().sort("name").show()
# +-----+-----+
# | name|count|
# +-----+-----+
# |Alice| 2|
# | Bob| 2|
# +-----+-----+