percentileOrNull

fun <T : Comparable<T & Any>?> DataColumn<T>.percentileOrNull(percentile: Double): T?

Returns the given percentile of the comparable values in this DataColumn, or null if there is nothing to compute the percentile of.

This overload is meant for non-number self-comparable values, like strings or dates. Columns of primitive numbers use the percentileOrNull overload with a skipNaN parameter, which returns an interpolated Double.

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.

Returns null 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.

See also:

  • percentile — throws instead of returning null for a column with nothing to compute the percentile of.

  • percentileOfOrNull — the percentile of the values an expression returns for each element.

  • percentileByOrNull — the element at the percentile of the values a selector returns.

  • medianOrNull — the median (50th percentile) of the values in this column.

  • The Percentile Operation — an overview of all percentile modes.

For more information: See percentile on the documentation website.

Example

// The third quartile of the cities in the "city" column (in alphabetical order),
// or `null` if the column contains no values other than `null`
df.city.percentileOrNull(75.0)

Return

The given percentile of the values in this column, or null if there are no values to compute the percentile of.

Parameters

percentile

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.


fun <T : Comparable<T & Any>?, Number?> DataColumn<T>.percentileOrNull(percentile: Double, skipNaN: Boolean = skipNaNDefault): Double?

Returns the given percentile of the numbers in this DataColumn, as a Double, or null if there is nothing to compute the percentile of.

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 NaN values, the result will be NaN, unless skipNaN is set to true.

Returns null 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, BigDecimal) 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; convert them to a primitive number type first.

For more information about the resulting types: See "percentile Type Conversion" on the documentation website.

See also:

  • percentile — throws instead of returning null for a column with nothing to compute the percentile of.

  • percentileOfOrNull — the percentile of the values an expression returns for each element.

  • percentileByOrNull — the element at the percentile of the values a selector returns.

  • medianOrNull — the median (50th percentile) of the values in this column.

  • The Percentile Operation — an overview of all percentile modes.

For more information: See percentile on the documentation website.

Example

// The third quartile of the weights in the "weight" column,
// or `null` if the column contains no values other than `null`
df.weight.percentileOrNull(75.0)

Return

The given percentile of the values in this column, as a Double, or null if there are no values to compute the percentile of.

Parameters

percentile

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.

skipNaN

If true, NaN values are ignored, just like null values. If false (the default), a NaN in the input is propagated to the result. This only has an effect on Double and Float values.


fun <T, C : Comparable<C & Any>?> DataFrame<T>.percentileOrNull(percentile: Double, columns: ColumnsSelector<T, C>): C?

Returns a single percentile of all the comparable values in the selected columns of this DataFrame, or null if there is nothing to compute the percentile of.

This overload is meant for non-number self-comparable values, like strings or dates. For columns of primitive numbers, the percentileOrNull 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.

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.

Returns null 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.

See also:

  • percentile — throws instead of returning null when there's nothing to compute the percentile of.

  • percentileFor — the percentile of each selected column separately.

  • percentileOfOrNull — the percentile of the values a row expression returns for each row.

  • medianOrNull — the median (50th percentile) of all values in the selected columns.

  • The Percentile Operation — an overview of all percentile modes.

For more information: See percentile on the documentation website.

Select or express columns using the Columns Selection DSL.

This DSL is initiated by a Columns Selector lambda, which operates in the context of the Columns Selection DSL and expects you to return a SingleColumn or ColumnSet (so, a ColumnsResolver). This is an entity formed by calling any (combination) of the functions in the DSL that is or can be resolved into one or more columns.

The Columns Selection DSL allows using Extension Properties for specifying columns type- and name-safe.

Check out: Columns Selection DSL Grammar

    

See Column Selectors on the documentation website.

Examples

// The first quartile of all first and last names in the "name" column group,
// or `null` if there are no values to compute the percentile of
df.percentileOrNull<_, String>(25.0) { name.firstName and name.lastName }
// The same, with the lambda inside the parentheses
df.percentileOrNull(25.0, { name.firstName and name.lastName })

Return

The given percentile of all the values in the selected columns, or null if there are no values to compute the percentile of.

Parameters

percentile

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.

columns

The ColumnsSelector used to select the columns to compute the percentile of.


fun <T, C : Comparable<C & Any>?, Number?> DataFrame<T>.percentileOrNull(percentile: Double, skipNaN: Boolean = skipNaNDefault, columns: ColumnsSelector<T, C>): Double?

Returns a single percentile of all the numbers in the selected columns of this DataFrame, as a Double, or null if there is nothing to compute the percentile of.

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 NaN values, the result will be NaN, unless skipNaN is set to true.

Returns null 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, BigDecimal) 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; convert them to a primitive number type first.

For more information about the resulting types: See "percentile Type Conversion" on the documentation website.

See also:

  • percentile — throws instead of returning null when there's nothing to compute the percentile of.

  • percentileFor — the percentile of each selected column separately.

  • percentileOfOrNull — the percentile of the values a row expression returns for each row.

  • medianOrNull — the median (50th percentile) of all values in the selected columns.

  • The Percentile Operation — an overview of all percentile modes.

For more information: See percentile on the documentation website.

Select or express columns using the Columns Selection DSL.

This DSL is initiated by a Columns Selector lambda, which operates in the context of the Columns Selection DSL and expects you to return a SingleColumn or ColumnSet (so, a ColumnsResolver). This is an entity formed by calling any (combination) of the functions in the DSL that is or can be resolved into one or more columns.

The Columns Selection DSL allows using Extension Properties for specifying columns type- and name-safe.

Check out: Columns Selection DSL Grammar

    

See Column Selectors on the documentation website.

Example

// The third quartile of all values in the "age" and "weight" columns,
// or `null` if there are no values to compute the percentile of
df.percentileOrNull(75.0) { age and weight }

Return

The given percentile of all the values in the selected columns, as a Double, or null if there are no values to compute the percentile of.

Parameters

percentile

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.

skipNaN

If true, NaN values are ignored, just like null values. If false (the default), a NaN in the input is propagated to the result. This only has an effect on Double and Float values.

columns

The ColumnsSelector used to select the columns to compute the percentile of.


fun <T> DataFrame<T>.percentileOrNull(percentile: Double, vararg columns: String, skipNaN: Boolean = skipNaNDefault): Any?

Returns a single percentile of all the values in the columns of this DataFrame with the given names, or null if there is nothing to compute the percentile of.

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 NaN values, the result will be NaN, unless skipNaN is set to true.

Returns null when there is nothing to compute the percentile of, for instance, when the input is empty or contains only null values.

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.

See also:

  • percentile — throws instead of returning null when there's nothing to compute the percentile of.

  • percentileFor — the percentile of each selected column separately.

  • medianOrNull — the median (50th percentile) of all values in the selected columns.

  • The Percentile Operation — an overview of all percentile modes.

For more information: See percentile on the documentation website.

Select single or multiple columns using their names as Strings. (String API).

Example

// The third quartile of all values in the "age" and "weight" columns, as a `Double`,
// or `null` if there are no values to compute the percentile of
df.percentileOrNull(75.0, "age", "weight")

Return

The given percentile of all the values in the selected columns, or null if there are no values to compute the percentile of.

Parameters

percentile

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.

columns

The names of the columns to compute the percentile of. These must be existing columns whose values are mutually comparable, else an IllegalStateException is thrown.

skipNaN

If true, NaN values are ignored, just like null values. If false (the default), a NaN in the input is propagated to the result. This only has an effect on Double and Float values.


fun <T, C : Comparable<C & Any>?> DataFrame<T>.percentileOrNull(percentile: Double, vararg columns: ColumnReference<C>): C?
fun <T, C : Comparable<C & Any>?, Number?> DataFrame<T>.percentileOrNull(percentile: Double, vararg columns: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): Double?
fun <T, C : Comparable<C & Any>?> DataFrame<T>.percentileOrNull(percentile: Double, vararg columns: KProperty<C>): C?
fun <T, C : Comparable<C & Any>?, Number?> DataFrame<T>.percentileOrNull(percentile: Double, vararg columns: KProperty<C>, skipNaN: Boolean = skipNaNDefault): Double?

Deprecated

It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html