---
title: count (GroupedData)
description: "GroupedData.count method in PySpark: Counts the number of records for each group."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/groupeddata/count
---

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