last

fun <T> DataColumn<T>.last(): T

Returns the last value in this DataColumn.

For more information: See last on the documentation website.

See also lastOrNull, first, take, takeLast, single.

Return

The last value in this DataColumn.

Throws


inline fun <T> DataColumn<T>.last(predicate: (T) -> Boolean): T

Returns the last value in this DataColumn that matches the given predicate.

Example

// In a DataFrame of financial transactions sorted by time,
// find the amount of the most recent financial transaction over 100 euros
df.amount.last { it > 100 }

For more information: See last on the documentation website.

See also lastOrNull, first, take, takeLast, single.

Return

The last value in this DataColumn that matches the given predicate.

Parameters

predicate

A lambda expression used to get the last value that satisfies a condition specified in this expression. This predicate takes a value from the DataColumn as an input and returns true if the value satisfies the condition or false otherwise.

Throws

if the DataColumn contains no element matching the predicate (including the case when the DataColumn is empty).


inline fun <T> DataFrame<T>.last(predicate: RowFilter<T>): DataRow<T>

Returns the last row in this DataFrame that satisfies 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.

This can include column groups and nested columns.

Example

// In a DataFrame of financial transactions sorted by time,
// find the most recent financial transaction with amount over 100 euros
df.last { amount > 100 }

For more information: See last on the documentation website.

See also lastOrNull, first, take, takeLast, takeWhile, single, that fails unless there is exactly one row to return.

Return

A DataRow containing the last row that matches the given predicate.

Parameters

predicate

A row filter used to get the last value that satisfies a condition specified in this filter.

Throws

if the DataFrame contains no rows matching the predicate.


fun <T> DataFrame<T>.last(): DataRow<T>

Returns the last row in this DataFrame.

For more information: See last on the documentation website.

See also lastOrNull, first, take, takeLast, single, that fails unless there is exactly one row to return.

Return

A DataRow containing the last row in this DataFrame.

Throws

if the DataFrame contains no rows.


fun <T, G> GroupBy<T, G>.last(): ReducedGroupBy<T, G>

Reduces the groups of this GroupBy by taking the last row from each group, and returns a ReducedGroupBy containing these rows (one row per group, each row is the last row in its group).

If a group in this GroupBy is empty, the corresponding row in the resulting ReducedGroupBy will contain null values for all columns in the group, except the grouping key.

Example

// In a DataFrame of order status logs sorted by time,
// find the most recent status for each order
df.groupBy { orderId }.last().concat()

For more information: See last on the documentation website.

For more information about GroupBy and last with examples: See groupBy on the documentation website.

See also first.

Return

A ReducedGroupBy containing the last row (or a row with null values, except the grouping key) from each group.


fun <T, G> GroupBy<T, G>.last(predicate: RowFilter<G>): ReducedGroupBy<T, G>

Reduces the groups of this GroupBy by taking from each group the last row satisfying the given predicate, and returns a ReducedGroupBy containing these rows (one row per group, each row is the last row in its group that satisfies the predicate).

If the group in GroupBy contains no matching rows, the corresponding row in ReducedGroupBy will contain null values for all columns in the group, except the grouping key.

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.

This can include column groups and nested columns.

Example

// In a DataFrame of order status logs sorted by time,
// find the most recent status shown to the customer for each order
df.groupBy { orderId }.last { !isInternal }.concat()

For more information: See last on the documentation website.

For more information about GroupBy and last with examples: See groupBy on the documentation website.

See also first.

Return

A ReducedGroupBy containing the last row matching the predicate (or a row with null values, except the grouping key) from each group.

Parameters

predicate

A row filter used to get the last value that satisfies a condition specified in this filter.


fun <T> Pivot<T>.last(): ReducedPivot<T>

Reduces this Pivot by taking the last row from each group, and returns a ReducedPivot that contains the last row from the corresponding group in each column.

For more information: See last on the documentation website.

For more information about Pivot and last with examples: See pivot on the documentation website.

Example

// In a DataFrame of real estate listings, find the most recent (if sorted by date and time)
// or the most expensive (if sorted by price) listing for each type of property (house, apartment, etc.)
df.pivot { type }.last().values()

See also pivot, reduce, first.

Return

A ReducedPivot containing in each column the last row from the corresponding group.


fun <T> Pivot<T>.last(predicate: RowFilter<T>): ReducedPivot<T>

Reduces this Pivot by taking from each group the last row satisfying the given predicate, and returns a ReducedPivot that contains the last row, matching the predicate, from the corresponding group in each column.

For more information: See last on the documentation website.

For more information about Pivot and last with examples: See pivot on the documentation website.

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.

This can include column groups and nested columns.

Example

// In a DataFrame of real estate listings sorted by date and time,
// find the most recent listing for each type of property (house, apartment, etc.)
// with the price less than 500,000 euros
df.pivot { type }.last { price < 500_000 }.values()

See also pivot, reduce, first.

Return

A ReducedPivot containing in each column the last row that satisfies the predicate, from the corresponding group (or a row with null values)

Parameters

predicate

A row filter used to get the last value that satisfies a condition specified in this filter.


Reduces this PivotGroupBy by taking the last row from each combined pivot + groupBy group, and returns a ReducedPivotGroupBy that contains the last row from each corresponding group. If any combined pivot + groupBy group in PivotGroupBy is empty, in the resulting ReducedPivotGroupBy it will be represented by a row with null values (except the grouping key).

For more information: See last on the documentation website.

For more information about PivotGroupBy with examples: See "pivot + groupBy" on the documentation website.

Example

// In a DataFrame of real estate listings sorted by date and time,
// find the most recent listing for each combination of type of property (house, apartment, etc.)
// and the city it is located in
df.pivot { type }.groupBy { city }.last().values()

See also groupBy, pivot, reduce, first.

Return

A ReducedPivotGroupBy containing in each combination of a groupBy key and a pivot key either the last row of the corresponding DataFrame formed by this pivot–group pair, or a row with null values (except the grouping key) if this DataFrame is empty.


Reduces this PivotGroupBy by taking from each combined pivot + groupBy group the last row satisfying the given predicate. Returns a ReducedPivotGroupBy that contains the last row, matching the predicate, from each corresponding group. If any combined pivot + groupBy group in PivotGroupBy does not contain any rows matching the predicate, in the resulting ReducedPivotGroupBy it will be represented by a row with null values (except the grouping key).

For more information: See last on the documentation website.

See "pivot + groupBy" on the documentation website.

See pivot on the documentation website.

See groupBy on the documentation website.

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.

This can include column groups and nested columns.

Example

// In a DataFrame of real estate listings sorted by date and time,
// for each combination of type of property (house, apartment, etc.)
// and the city it is located in,
// find the most recent listing with the price less than 500,000 euros
df.pivot { type }.groupBy { city }.last { price < 500_000 }.values()

See also groupBy, pivot, reduce, first.

Return

A ReducedPivotGroupBy containing in each combination of a groupBy key and a pivot key either the last matching the predicate row of the corresponding DataFrame formed by this pivot–group pair, or a row with null values if this DataFrame does not contain any rows matching the predicate.

Parameters

predicate

A row filter used to get the last value that satisfies a condition specified in this filter.