llms.txt: machine-readable documentation index. Markdown version of this page is also available.

DataFrame Help

filter

Keeps only the rows of a DataFrame that satisfy a row condition. The order of the kept rows doesn't change.

Returns a new DataFrame with the rows that satisfy the condition. If no row satisfies it, the result is an empty DataFrame with the same columns.

df.filter { DataRow.(DataRow) -> Boolean }

The row condition receives each row both as this and as it, so the values of the row can be accessed directly using Extension Properties or String column accessors, including the values of nested columns of a ColumnGroup.

See also:

API reference: filter

Parameters

  • predicate: DataRow.(DataRow) -> Boolean — a row condition that returns true if the row should be kept in the result.

Examples

The following dataframe will be used in the examples below. The rows that satisfy the condition from the next example are highlighted:

df

Keep only the people older than 18 whose first name starts with "A":

df.filter { age > 18 && name.firstName.startsWith("A") }
df.filter { "age"<Int>() > 18 && "name"["firstName"]<String>().startsWith("A") }

The row can also be taken as an explicit lambda parameter instead of it.

Besides the row values, the row condition can use the DataRow API — for example, the index of the row and the previous row. Keep the people starting from the third row whose previous person is happy:

df.filter { row -> row.index() >= 2 && row.prev()!!.isHappy }

filter on DataColumn

Keeps only the values of a DataColumn that satisfy the given predicate.

Returns a new DataColumn with the same name, containing only the matching values in their original order.

col.filter { value -> Boolean }

Parameters

  • predicate: (value) -> Boolean — a lambda that receives a value of the column and returns true if the value should be kept in the result.

Examples

Keep only the ages greater than 17:

df.age.filter { it > 17 }
02 November 2026