minBy
Returns the first element of this DataColumn for which the given selector returns the minimum value.
The result of the expression is considered the 'input' of this operation.
Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
Throws a NoSuchElementException when there is nothing left to compare, for instance when the input is empty or contains only null (or, if skipNaN is true, only null and ) values.NaN
Don't confuse minBy with minOf, which returns the minimum selector value itself instead of the element it belongs to.
See also:
minByOrNull— returnsnullinstead of throwing for a column with nothing to compare.maxBy— the mirror operation.The Min Operation— an overview of allminmodes.
For more information: See minBy on the documentation website.
Example
// The shortest first name in the "name"/"firstName" column
df.name.firstName.minBy { it.length }Return
The first element for which selector returns the minimum value.
Parameters
A function that returns the value to compare for each element of this column.
Throws
if there are no values to compare.
Returns the first row of this DataFrame for which the given expression returns the minimum value.
The given RowExpression is evaluated for each row of the dataframe. The row is both the receiver and the argument (it) of the expression, so the values in it can be accessed directly.
For more information: See RowExpression on the documentation website.
The result of the expression is considered the 'input' of this operation.
Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
Throws a NoSuchElementException when there is nothing left to compare, for instance when the input is empty or contains only null (or, if skipNaN is true, only null and ) values.NaN
Don't confuse minBy with minOf, which returns the minimum expression value itself instead of the row it belongs to.
See also:
minByOrNull— returnsnullinstead of throwing when there's nothing to compare.maxBy— the mirror operation.sortBy— orders all rows instead of taking just the smallest one.The Min Operation— an overview of allminmodes.
For more information: See minBy on the documentation website.
Example
// The row with the smallest "age"
df.minBy { age }
// The row with the smallest weight-to-age ratio
df.minBy { (weight ?: 0) / age }Return
The first DataRow for which expression returns the minimum value.
Parameters
The RowExpression to compute the value to compare for each row.
Throws
if there are no values to compare.
Returns the first row of this DataFrame that has the smallest value in the column with the given name.
Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
Throws a NoSuchElementException when there is nothing left to compare, for instance when the input is empty or contains only null (or, if skipNaN is true, only null and ) values.NaN
Don't confuse minBy with minOf, which returns the minimum value a row expression returns itself, instead of the row it belongs to.
See also:
minByOrNull— returnsnullinstead of throwing when there's nothing to compare.min— returns the smallest value itself instead of the row it belongs to.maxBy— the mirror operation.sortBy— orders all rows instead of taking just the smallest one.The Min Operation— an overview of allminmodes.
For more information: See minBy on the documentation website.
Example
// The row with the smallest "age"
df.minBy("age")Return
The first DataRow with the smallest value in the given column.
Parameters
The name of the column of this DataFrame to compare the rows by.
Throws
if there are no values to compare.
Reduces each group of this GroupBy to the first row for which the given rowExpression returns the minimum value.
This operation does not produce a result right away. Instead, it returns a ReducedGroupBy — an intermediate step which can be finished with concat (to get a DataFrame with the selected rows), values, or into.
See GroupBy reducing for more details.
The given RowExpression is evaluated for each row of the dataframe. The row is both the receiver and the argument (it) of the expression, so the values in it can be accessed directly.
For more information: See RowExpression on the documentation website.
The result of the expression is considered the 'input' of this operation.
Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
Groups that have no values to compare cannot select a row, and produce null values instead.
Don't confuse minBy with minOf, which returns the minimum value itself instead of the row it belongs to.
See also:
maxBy— the mirror operation.The Min Operation— an overview of allminmodes.
For more information: See minBy on the documentation website.
Example
// For each city, the full row of the person with the smallest "age"
df.groupBy { city }.minBy { age }.concat()Return
A ReducedGroupBy with, for each group, the first row for which rowExpression returns the minimum value.
Parameters
The RowExpression to compute the value to compare for each row.
Reduces each group of this GroupBy to the first row that has the smallest value in the column with the given name.
This operation does not produce a result right away. Instead, it returns a ReducedGroupBy — an intermediate step which can be finished with concat (to get a DataFrame with the selected rows), values, or into.
See GroupBy reducing for more details.
Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
Groups that have no values to compare cannot select a row, and produce null values instead.
Don't confuse minBy with minOf, which returns the minimum value a row expression returns itself, instead of the row it belongs to.
See also:
min— the minimum value itself instead of the row it belongs to.maxBy— the mirror operation.The Min Operation— an overview of allminmodes.
For more information: See minBy on the documentation website.
Example
// For each city, the full row of the person with the smallest "age"
df.groupBy { city }.minBy("age").concat()Return
A ReducedGroupBy with, for each group, the first row that has the smallest value in the given column.
Parameters
The name of the column to compare the rows by.
Reduces this Pivot by taking from each group the first row for which the given rowExpression returns the minimum value.
The given RowExpression is evaluated for each row of the dataframe. The row is both the receiver and the argument (it) of the expression, so the values in it can be accessed directly.
For more information: See RowExpression on the documentation website.
The result of the expression is considered the 'input' of this operation.
Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
Groups that have no values to compare cannot select a row, and produce null values instead.
This operation does not produce a result right away. Instead, it returns a ReducedPivot — an intermediate step which can be finished with values or with.
Don't confuse minBy with minOf, which returns the minimum value the expression returns itself, instead of the row.
Check out the .Pivot Grammar
See also:
maxBy— the mirror operation.Pivot reducing— all other ways to reduce aPivot.The Min Operation— an overview of allminmodes.
For more information: See minBy on the documentation website.
Example
// For each city, the "name" of the person with the smallest weight-to-age ratio
df.pivot { city }.minBy { (weight ?: 0) / age }.with { name }Return
A ReducedPivot holding, per group, the first row where the rowExpression produced the minimum result.
Parameters
The RowExpression to evaluate for each row.
Reduces this Pivot by taking from each group the first row that has the smallest value in the given column.
Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
Groups that have no values to compare cannot select a row, and produce null values instead.
This operation does not produce a result right away. Instead, it returns a ReducedPivot — an intermediate step which can be finished with values or with.
Don't confuse minBy with minOf, which returns the minimum value a row expression returns itself, instead of the row.
Check out the .Pivot Grammar
See also:
min{ columns }— the minimum value itself, instead of the row.maxBy— the mirror operation.Pivot reducing— all other ways to reduce aPivot.The Min Operation— an overview of allminmodes.
For more information: See minBy on the documentation website.
Example
// For each city, the "name" of the youngest person
df.pivot { city }.minBy("age").with { name }Return
A ReducedPivot holding, per group, the first row with the smallest value in the given column.
Parameters
The name of the column to compare the rows by.
Reduces this PivotGroupBy by taking from each group the first row for which the given rowExpression returns the minimum value.
The given RowExpression is evaluated for each row of the dataframe. The row is both the receiver and the argument (it) of the expression, so the values in it can be accessed directly.
For more information: See RowExpression on the documentation website.
The result of the expression is considered the 'input' of this operation.
Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
Groups that have no values to compare cannot select a row, and produce null values instead.
This operation does not produce a result right away. Instead, it returns a ReducedPivotGroupBy — an intermediate step which can be finished with values or with.
Don't confuse minBy with minOf, which returns the minimum value the expression returns itself, instead of the row.
Check out the .PivotGroupBy Grammar
See also:
maxBy— the mirror operation.PivotGroupBy reducing— all other ways to reduce aPivotGroupBy.The Min Operation— an overview of allminmodes.
For more information: See minBy on the documentation website.
Example
// Per city and last name, the "firstName" of the person with the smallest weight-to-age ratio
df.pivot { city }.groupBy { name.lastName }.minBy { (weight ?: 0) / age }.with { name.firstName }Return
A ReducedPivotGroupBy holding, per group, the first row where the rowExpression produced the minimum result.
Parameters
The RowExpression to evaluate for each row.
Reduces this PivotGroupBy by taking from each group the first row that has the smallest value in the given column.
Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
Groups that have no values to compare cannot select a row, and produce null values instead.
This operation does not produce a result right away. Instead, it returns a ReducedPivotGroupBy — an intermediate step which can be finished with values or with.
Don't confuse minBy with minOf, which returns the minimum value a row expression returns itself, instead of the row.
Check out the .PivotGroupBy Grammar
See also:
min{ columns }— the minimum value itself, instead of the row.maxBy— the mirror operation.PivotGroupBy reducing— all other ways to reduce aPivotGroupBy.The Min Operation— an overview of allminmodes.
For more information: See minBy on the documentation website.
Example
// Per city and last name, the "firstName" of the youngest person
df.pivot { city }.groupBy { name.lastName }.minBy("age").with { name.firstName }Return
A ReducedPivotGroupBy holding, per group, the first row with the smallest value in the given column.
Parameters
The name of the column to compare the rows by.
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html