percentileOf
Returns the given percentile of the comparable values that the given expression returns for each element of this DataColumn.
This overload is meant for expressions returning non-number self-comparable values, like strings or dates. For expressions returning primitive numbers, the percentileOf overload with a skipNaN parameter is used, which returns an interpolated Double.
Note: Due to a limitation in Kotlin's overload resolution (KT-76683), calling this overload with a lambda returning non-number comparable values, like strings or dates, requires either explicit type arguments, or passing the lambda inside the parentheses (see the examples below). For a lambda returning primitive numbers, the overload returning a Double is picked automatically.
From Kotlin 2.5, this limitation can be lifted by enabling eager lambda analysis (KT-51107) with the compiler option -XXLanguage:+EagerLambdaAnalysis, like kotlin { compilerOptions { freeCompilerArgs.add("-XXLanguage:+EagerLambdaAnalysis") } } in Gradle. Then, the right overload is picked for lambdas returning non-number comparable values too, without explicit type arguments. Note that this is an internal compiler option without any stability guarantees, so it is not recommended for production use yet.
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.
Throws a NoSuchElementException when there is nothing to compute the percentile of, for instance, when the input is empty or contains only null values.
The resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as the values (minus nullability, if the values were nullable).
Currently, only the default quantile estimation methods can be used. In the future, it might become possible to choose a different one, see #1121.
For more information about the resulting types: See "percentile Type Conversion" on the documentation website.
Don't confuse percentileOf with percentileBy, which returns the element the percentile of the expression values belongs to instead of that value.
See also:
percentileOfOrNull— returnsnullinstead of throwing for a column with nothing to compute the percentile of.medianOf— the median (50th percentile) of the values an expression returns.The Percentile Operation— an overview of allpercentilemodes.
For more information: See percentile on the documentation website.
Examples
// The first quartile of all last names in the "name" column group, in upper case
df.name.percentileOf<_, String>(25.0) { it.lastName.uppercase() }
// The same, with the lambda inside the parentheses
df.name.percentileOf(25.0, { it.lastName.uppercase() })Return
The given percentile of the values expression returns.
Parameters
The percentile to compute, in the range [0.0, 100.0], like 25.0 for the first quartile, 50.0 for the median, or 75.0 for the third quartile. A percentile outside this range causes an IllegalStateException.
A function that returns the value to include for each element of this column.
Throws
if there are no values to compute the percentile of.
Returns the given percentile of the numbers that the given expression returns for each element of this DataColumn, as a Double.
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 to compute the percentile of, for instance, when the input is empty or contains only null values.
The resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values.
Currently, only the default quantile estimation methods can be used. In the future, it might become possible to choose a different one, see #1121.
Big numbers (, BigInteger) are not explicitly supported. They are self-comparable, so some overloads select a value without interpolating it, while others throw an exception at runtime. Don't rely on this; BigDecimal them to a primitive number type first.convert
For more information about the resulting types: See "percentile Type Conversion" on the documentation website.
Don't confuse percentileOf with percentileBy, which returns the element the percentile of the expression values belongs to instead of that value.
See also:
percentileOfOrNull— returnsnullinstead of throwing for a column with nothing to compute the percentile of.medianOf— the median (50th percentile) of the values an expression returns.The Percentile Operation— an overview of allpercentilemodes.
For more information: See percentile on the documentation website.
Example
// The 90th percentile of the lengths of all first names in the "name"/"firstName" column
df.name.firstName.percentileOf(90.0) { it.length }Return
The given percentile of the values expression returns, as a Double.
Parameters
The percentile to compute, in the range [0.0, 100.0], like 25.0 for the first quartile, 50.0 for the median, or 75.0 for the third quartile. A percentile outside this range causes an IllegalStateException.
A function that returns the value to include for each element of this column.
Throws
if there are no values to compute the percentile of.
Returns the given percentile of the comparable values that the given expression returns for each row of this DataFrame.
This overload is meant for expressions returning non-number self-comparable values, like strings or dates. For expressions returning primitive numbers, the percentileOf overload with a skipNaN parameter is used, which returns an interpolated Double.
Note: Due to a limitation in Kotlin's overload resolution (KT-76683), calling this overload with a lambda returning non-number comparable values, like strings or dates, requires either explicit type arguments, or passing the lambda inside the parentheses (see the examples below). For a lambda returning primitive numbers, the overload returning a Double is picked automatically.
From Kotlin 2.5, this limitation can be lifted by enabling eager lambda analysis (KT-51107) with the compiler option -XXLanguage:+EagerLambdaAnalysis, like kotlin { compilerOptions { freeCompilerArgs.add("-XXLanguage:+EagerLambdaAnalysis") } } in Gradle. Then, the right overload is picked for lambdas returning non-number comparable values too, without explicit type arguments. Note that this is an internal compiler option without any stability guarantees, so it is not recommended for production use yet.
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.
Throws a NoSuchElementException when there is nothing to compute the percentile of, for instance, when the input is empty or contains only null values.
The resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as the values (minus nullability, if the values were nullable).
Currently, only the default quantile estimation methods can be used. In the future, it might become possible to choose a different one, see #1121.
For more information about the resulting types: See "percentile Type Conversion" on the documentation website.
Don't confuse percentileOf with percentileBy, which returns the row the percentile of the expression values belongs to instead of that value.
See also:
percentileOfOrNull— returnsnullinstead of throwing when there's nothing to compute the percentile of.percentile— a single percentile of all values in the selected columns.medianOf— the median (50th percentile) of the values a row expression returns.The Percentile Operation— an overview of allpercentilemodes.
For more information: See percentile on the documentation website.
Examples
// The first quartile of the full names of all rows
df.percentileOf<_, String>(25.0) { name.firstName + " " + name.lastName }
// The same, with the lambda inside the parentheses
df.percentileOf(25.0, { name.firstName + " " + name.lastName })Return
The given percentile of the values expression returns.
Parameters
The percentile to compute, in the range [0.0, 100.0], like 25.0 for the first quartile, 50.0 for the median, or 75.0 for the third quartile. A percentile outside this range causes an IllegalStateException.
The RowExpression to compute the value to include for each row.
Throws
if there are no values to compute the percentile of.
Returns the given percentile of the numbers that the given expression returns for each row of this DataFrame, as a Double.
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 to compute the percentile of, for instance, when the input is empty or contains only null values.
The resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values.
Currently, only the default quantile estimation methods can be used. In the future, it might become possible to choose a different one, see #1121.
Big numbers (, BigInteger) are not explicitly supported. They are self-comparable, so some overloads select a value without interpolating it, while others throw an exception at runtime. Don't rely on this; BigDecimal them to a primitive number type first.convert
For more information about the resulting types: See "percentile Type Conversion" on the documentation website.
Don't confuse percentileOf with percentileBy, which returns the row the percentile of the expression values belongs to instead of that value.
See also:
percentileOfOrNull— returnsnullinstead of throwing when there's nothing to compute the percentile of.percentile— a single percentile of all values in the selected columns.medianOf— the median (50th percentile) of the values a row expression returns.The Percentile Operation— an overview of allpercentilemodes.
For more information: See percentile on the documentation website.
Example
// The third quartile of the weight-to-age ratios of all rows
df.percentileOf(75.0) { (weight ?: 0) / age }Return
The given percentile of the values expression returns, as a Double.
Parameters
The percentile to compute, in the range [0.0, 100.0], like 25.0 for the first quartile, 50.0 for the median, or 75.0 for the third quartile. A percentile outside this range causes an IllegalStateException.
The RowExpression to compute the value to include for each row.
Throws
if there are no values to compute the percentile of.
Aggregates this GroupBy by computing the given percentile of the values that the given expression returns for each row of a group.
Returns a new DataFrame with one row per group, containing the group key columns and a single column with the percentile per group, named name (or "percentile" if name is null).
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.
For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.
Currently, only the default quantile estimation methods can be used. In the future, it might become possible to choose a different one, see #1121.
For more information about the resulting types: See "percentile Type Conversion" on the documentation website.
Result cells for which there is nothing to compute the percentile of (for instance, because the input was empty or contained only null values) simply become null.
Don't confuse percentileOf with percentileBy, which returns the row of each group at the percentile of the values the expression returns, instead of that value.
See also:
percentile— a single percentile of all values in the selected columns, per group.medianOf— the median (50th percentile) of the values a row expression returns, per group.aggregate— the general way to aggregate groups.The Percentile Operation— an overview of allpercentilemodes.
For more information: See "groupBy statistics" on the documentation website., and See "GroupBy Aggregation Statistics" on the documentation website.
Example
// For each city, the third quartile of the weight-to-age ratios, in a column called "q3Ratio"
df.groupBy { city }.percentileOf(75.0, "q3Ratio") { (weight ?: 0) / age }Return
A new DataFrame with the group keys and a single percentile per group.
Parameters
The percentile to compute, in the range [0.0, 100.0], like 25.0 for the first quartile, 50.0 for the median, or 75.0 for the third quartile. A percentile outside this range causes an IllegalStateException.
The name of the resulting column. If null (the default), "percentile" is used. This name needs to be unique, else a DuplicateColumnPathInsertException is thrown.
The RowExpression to compute the value to include for each row.
Aggregates this Pivot by computing the given percentile of the values that the given expression returns for each row, per group.
Returns a single DataRow with the pivot keys as (nested) columns, containing the percentile of the expression's results for the rows of the corresponding group.
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.
For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.
Currently, only the default quantile estimation methods can be used. In the future, it might become possible to choose a different one, see #1121.
For more information about the resulting types: See "percentile Type Conversion" on the documentation website.
Result cells for which there is nothing to compute the percentile of (for instance, because the input was empty or contained only null values) simply become null.
Don't confuse percentileOf with percentileBy, which returns the row of each group at the percentile of the values the expression returns, instead of that value.
Check out the .Pivot Grammar
See also:
percentile(percentile) { columns }— a single percentile of all values in the selected columns, per group.Pivot aggregation— all other ways to aggregate aPivot.The Percentile Operation— an overview of allpercentilemodes.
For more information: See "pivot statistics" on the documentation website., and See "Pivot Aggregation statistics" on the documentation website.
Example
// For each city, the third quartile of the weight-to-age ratios
df.pivot { city }.percentileOf(75.0) { (weight ?: 0) / age }Return
A single DataRow with, per pivot group, the given percentile of the expression's results.
Parameters
The percentile to compute, in the range [0.0, 100.0], like 25.0 for the first quartile, 50.0 for the median, or 75.0 for the third quartile. A percentile outside this range causes an IllegalStateException.
The RowExpression to compute the value to include for each row.
Aggregates this PivotGroupBy by computing the given percentile of the values that the given expression returns for each row, per group.
Returns a DataFrame where each cell contains the percentile of the expression's results for the rows of the group corresponding to that pivot key (column) and groupBy key (row).
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.
For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.
Currently, only the default quantile estimation methods can be used. In the future, it might become possible to choose a different one, see #1121.
For more information about the resulting types: See "percentile Type Conversion" on the documentation website.
Result cells for which there exists a group, but there is nothing to compute the percentile of (for instance, because the group was empty or contained only null values) simply become null.
For empty pivot intersections, null or the set default is used.
Don't confuse percentileOf with percentileBy, which returns the row of each group at the percentile of the values the expression returns, instead of that value.
Check out the .PivotGroupBy Grammar
See also:
percentile(percentile) { columns }— a single percentile of all values in the selected columns, per group.PivotGroupBy aggregation— all other ways to aggregate aPivotGroupBy.The Percentile Operation— an overview of allpercentilemodes.
For more information: See "pivot statistics" on the documentation website., and See "Pivot Aggregation statistics" on the documentation website.
Example
// Per city and last name, the third quartile of the weight-to-age ratios
df.pivot { city }.groupBy { name.lastName }.percentileOf(75.0) { (weight ?: 0) / age }Return
A DataFrame with, per pivot and groupBy group, the given percentile of the expression's results.
Parameters
The percentile to compute, in the range [0.0, 100.0], like 25.0 for the first quartile, 50.0 for the median, or 75.0 for the third quartile. A percentile outside this range causes an IllegalStateException.
The RowExpression to compute the value to include for each row.