# count

> For the complete documentation index, see [llms.txt](https://kotlin.github.io/dataframe/llms.txt).

Counts the number of rows.

API reference: [count](https://kotlin.github.io/dataframe/api-docs/core/org.jetbrains.kotlinx.dataframe.api/count.html)

```KOTLIN
df
```

[Embedded content](./resources/countDf.html)

```KOTLIN
df.count() // the result is 10
```

Pass a [row condition](datarow.html#row-conditions) to count only the number of rows that satisfy that condition:

Properties:

```KOTLIN
df.count { age > 15 } // the result is 8
```

Strings:

```KOTLIN
df.count { "age"<Int>() > 15 } // the result is 8
```

##  On a [GroupBy](groupby.html), [Pivot](pivot.html), [PivotGroupBy](pivot.html#pivot-groupby) 

When `count` is used in [groupBy](groupby.html#aggregation), [pivot](pivot.html#aggregation), or [pivotGroupBy](pivot.html#pivot-groupby) aggregations, it counts rows for every data group:

Properties:

```KOTLIN
df.groupBy { city }.count()
```

Strings:

```KOTLIN
df.groupBy("city").count()
```

[Embedded content](./resources/countGroupBy.html)

Properties:

```KOTLIN
df.pivot { city }.count { age > 18 }
```

Strings:

```KOTLIN
df.pivot("city").count { "age"<Int>() > 18 }
```

[Embedded content](./resources/countPivot.html)

Properties:

```KOTLIN
df.pivot { name.firstName }.groupBy { name.lastName }.count()
```

Strings:

```KOTLIN
df.pivot { "name"["firstName"] }
    .groupBy { "name"["lastName"] }
    .count()
```

[Embedded content](./resources/countPivotGroupBy.html)

##  On a [DataRow](datarow.html) 

When called on a [DataRow](datarow.html), returns the number of columns in this [DataRow](datarow.html).

```KOTLIN
df[0].count() // the result is 5
```

If a predicate is used, it counts the number of elements in the row that satisfy the given predicate.

```KOTLIN
df[2].count { it == null } // the result is 1
```

##  On a [DataColumn](datacolumn.html) 

When called on a [DataColumn](datacolumn.html), returns either the count of elements in the column that match the predicate, or the total count of elements if no predicate is provided.

```KOTLIN
df.age.count() // the result is 10
```

```KOTLIN
df.age.count { it > 17 } // the result is 8
```

