count

fun <T> DataColumn<T>.count(predicate: Predicate<T>? = null): Int

Counts the elements in this DataColumn that satisfy a given predicate or returns the total count if no predicate is provided.

For more information: See count on the documentation website.

Return

The count of elements in the column that either match the predicate or the total count of elements if no predicate is provided.

Parameters

predicate

An optional predicate used to filter the elements. The predicate should return true for elements to be counted. If null (by default), all elements are counted.


fun DataRow<*>.count(): Int

Returns the number of columns in this DataRow.

For more information: See count on the documentation website. See Row Functions on the documentation website.

Return

the number of columns in this row.

See also


inline fun DataRow<*>.count(predicate: Predicate<Any?>): Int

Counts the number of elements in the current row that satisfy the given predicate.

For more information: See count on the documentation website. See Row Functions on the documentation website.

Return

The number of elements that satisfy the predicate.

Parameters

predicate

A predicate function to test each element. The predicate should return true for elements to be counted.


fun <T> DataFrame<T>.count(): Int

Returns the total number of rows of this DataFrame.

For more information: See count on the documentation website.

Return

The number of rows in the DataFrame.


inline fun <T> DataFrame<T>.count(predicate: RowFilter<T>): Int

Counts the number of rows in this DataFrame that satisfy the given predicate.

The predicate is a RowFilter — a lambda that receives each DataRow as both this and it and is expected to return a Boolean value.

It allows you to define conditions using the row's values directly, including through extension properties for convenient and type-safe access.

For more information, See RowFilter on the documentation website.

See also:

For more information: See count on the documentation website.

Example

// Count rows where the value in the "age" column is greater than 18
// and the "name/firstName" column starts with 'A'
df.count { age > 18 && name.firstName.startsWith("A") }
// Count rows
df.count { prev()?.length >= 50.0 ?: false }

Return

The number of rows that satisfy the predicate.

Parameters

predicate

A RowFilter that returns true for rows that should be counted.

Type Parameters

T

The schema marker type of the DataFrame.


fun <T> Grouped<T>.count(resultName: String = "count"): DataFrame<T>

Aggregates this GroupBy by counting the number of rows in each group.

Returns a new DataFrame where each row corresponds to a group. The resulting frame contains:

  • the original group key columns,

  • a new column (named resultName, default is "count") that contains the number of rows in each group.

This is equivalent to applying .aggregate { count() }, but more efficient.

See also DataFrame.groupBy and common aggregate.

For more information: See count on the documentation website.

Example

// Counts number of rows for each city, returning
// a new DataFrame with columns "city" and "count"
df.groupBy { city }.count()

Return

A new DataFrame with group keys and corresponding group sizes.

Parameters

resultName

The name of the result column that will store the group sizes. Defaults to "count".


inline fun <T> Grouped<T>.count(resultName: String = "count", crossinline predicate: RowFilter<T>): DataFrame<T>

Aggregates this GroupBy by counting the number of rows in each group that satisfy the given predicate.

The predicate is a RowFilter — a lambda that receives each DataRow as both this and it and is expected to return a Boolean value.

It allows you to define conditions using the row's values directly, including through extension properties for convenient and type-safe access.

For more information, See RowFilter on the documentation website.

Returns a new DataFrame where each row corresponds to a group. The resulting frame contains:

  • the original group key columns,

  • a new column (named resultName, defaults to "count") that stores the number of rows in each group matching the predicate.

This is equivalent to calling .aggregate { count(predicate) }, but more efficient.

See also DataFrame.groupBy and common aggregate.

For more information: See count on the documentation website.

Example

// Count rows for each city where the "income" value is greater than 30.0.
// Returns a new DataFrame with columns "city" and "pointsCount".
df.groupBy { city }.count("pointsCount") { income >= 30.0 }

Return

A new DataFrame with group keys and filtered row counts per group.

Parameters

resultName

The name of the result column containing the group sizes. Defaults to "count".


fun <T> Pivot<T>.count(): DataRow<T>

Aggregates this Pivot by counting the number of rows in each group.

Returns a single DataRow where:

  • each column corresponds to a pivot group — if multiple pivot keys were used, the result will contain column groups for each pivot key, with columns inside corresponding to the values of that key;

  • each value contains the number of rows in that group.

The original Pivot column structure is preserved. If the Pivot was created using multiple or nested keys (e.g., via and or then), the structure remains unchanged — only the contents of each group are replaced with the number of rows in that group.

This is equivalent to calling .aggregate { count() }, but more efficient.

See also:

For more information: See count on the documentation website.

Example

// Count the number of rows for each city.
// Returns a single DataRow with one column per city and the count of rows in each.
df.pivot { city }.count()

Return

A single DataRow with one column per group and the corresponding group size as its value.


inline fun <T> Pivot<T>.count(crossinline predicate: RowFilter<T>): DataRow<T>

Aggregates this Pivot by counting the number of rows in each group that satisfy the given predicate.

The predicate is a RowFilter — a lambda that receives each DataRow as both this and it and is expected to return a Boolean value.

It allows you to define conditions using the row's values directly, including through extension properties for convenient and type-safe access.

For more information, See RowFilter on the documentation website.

Returns a single DataRow where:

  • each column corresponds to a pivot group — if multiple pivot keys were used, the result will contain column groups for each pivot key, with columns inside corresponding to the values of that key;

  • each value contains the number of rows in that group matching the predicate.

The original Pivot column structure is preserved. If the Pivot was created using multiple or nested keys (e.g., via and or then), the structure remains unchanged — only the contents of each group are replaced with the number of rows (matching the predicate) in that group.

This is equivalent to calling .aggregate { count(predicate) }, but more efficient.

See also:

For more information: See count on the documentation website.

Example

// Count rows for each city where the "income" value is greater than 30.0.
// Returns a single DataRow with one column per city and the count of matching rows.
df.pivot { city }.count { income > 30.0 }

Return

A single DataRow with original Pivot columns and filtered row counts per group.


Aggregates this PivotGroupBy by counting the number of rows in each combined pivot + groupBy group.

Returns a new DataFrame containing a following matrix:

  • one row per groupBy key (or keys set);

  • one column group per pivot key, where each inner column corresponds to a value of that key;

  • each cell contains the number of rows in the corresponding pivot–group pair.

The original Pivot column structure is preserved. If the Pivot was created using multiple or nested keys (e.g., via and or then), the result will contain nested column groups reflecting that key structure, with each group containing columns for the values of the corresponding key.

This is equivalent to calling .aggregate { count() }, but more efficient.

See also:

For more information: See count on the documentation website.

Example

// Compute a matrix with "city" values horizontally and
// "age" values vertically, where each cell contains
// the number of rows with the corresponding age–city pair.
df.pivot { city }.groupBy { age }.count()

Return

A DataFrame with groupBy rows and pivoted counts as columns.


inline fun <T> PivotGroupBy<T>.count(crossinline predicate: RowFilter<T>): DataFrame<T>

Aggregates this PivotGroupBy by counting the number of rows in each combined pivot + groupBy group, that satisfy the given predicate.

Returns a new DataFrame containing a following matrix:

  • one row per groupBy key (or keys set);

  • one column group per pivot key, where each inner column corresponds to a value of that key;

  • each cell contains the number of rows in the corresponding pivot–group pair.

The original Pivot column structure is preserved. If the Pivot was created using multiple or nested keys (e.g., via and or then), the result will contain nested column groups reflecting that key structure, with each group containing columns for the values (matching the predicate) of the corresponding key.

This is equivalent to calling .aggregate { count() }, but more efficient.

See also:

For more information: See count on the documentation website.

Example

// Compute a matrix with "city" values horizontally and
// "age" values vertically, where each cell contains
// the number of rows with the corresponding age–city pair.
df.pivot { city }.groupBy { age }.count()

Return

A DataFrame with groupBy rows and pivoted counts as columns matching the predicate..


@get:JvmName(name = "ColumnDescription_count")
val ColumnsScope<ColumnDescription>.count: DataColumn<Int>
@get:JvmName(name = "ColumnDescription_count")
val DataRow<ColumnDescription>.count: Int
@get:JvmName(name = "NullableColumnDescription_count")
val ColumnsScope<ColumnDescription?>.count: DataColumn<Int?>
@get:JvmName(name = "NullableColumnDescription_count")
val DataRow<ColumnDescription?>.count: Int?
@get:JvmName(name = "ValueCount_count")
val ColumnsScope<ValueCount>.count: DataColumn<Int>
@get:JvmName(name = "ValueCount_count")
val DataRow<ValueCount>.count: Int
@get:JvmName(name = "NullableValueCount_count")
val ColumnsScope<ValueCount?>.count: DataColumn<Int?>
@get:JvmName(name = "NullableValueCount_count")
val DataRow<ValueCount?>.count: Int?