medianFor
Returns the median of the values of each selected column of this DataFrame separately.
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 median 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 median 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 "median Type Conversion" on the documentation website.
Result cells for which there is nothing to compute the median of (for instance, because the input was empty or contained only null values) simply become null.
The columns are selected with the ColumnsForAggregateSelectionDsl — an extension of the Columns Selection DSL which lets you rename the result of a column with and supply a into value for columns without any values.default
See Selecting Columns.
See also:
median()— the same, but for all suitable columns at once.median{ columns }— a single median of all values in the selected columns.— any other percentile of each selected column.percentileForThe Median Operation— an overview of allmedianmodes.
For more information: See median on the documentation website.
Example
// A single row with the median "age" and the median "weight"
df.medianFor { age and weight }
// The same, ignoring `NaN` values, and naming the results explicitly
df.medianFor(skipNaN = true) { age into "medianAge" and (weight into "medianWeight") }Return
A single DataRow with the median of each selected column.
Parameters
The ColumnsForAggregateSelector used to select the columns to compute the median of.
Returns the median of the values of each selected column of this DataFrame separately.
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 median 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 median 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 "median Type Conversion" on the documentation website.
Result cells for which there is nothing to compute the median of (for instance, because the input was empty or contained only null values) simply become null.
See Selecting Columns.
See also:
median()— the same, but for all suitable columns at once.median{ columns }— a single median of all values in the selected columns.— any other percentile of each selected column.percentileForThe Median Operation— an overview of allmedianmodes.
For more information: See median on the documentation website.
Example
// A single row with the median "age" and the median "weight"
df.medianFor("age", "weight")Return
A single DataRow with the median of each selected column.
Parameters
The names of the columns to compute the median of. These must be existing columns holding self-comparable values, else an IllegalStateException is thrown.
Aggregates this GroupBy by computing the median of the values of each selected column separately, per group.
Returns a new DataFrame with one row per group, containing the group key columns and a column with the median for each selected 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.
For primitive numbers, the resulting median 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 median 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 "median Type Conversion" on the documentation website.
Result cells for which there is nothing to compute the median of (for instance, because the input was empty or contained only null values) simply become null.
The columns are selected with the ColumnsForAggregateSelectionDsl — an extension of the Columns Selection DSL which lets you rename the result of a column with and supply a into value for columns without any values.default
See Selecting Columns.
See also:
median()— the same, but for all suitable columns at once.median{ columns }— a single median of all values in the selected columns, per group.— the general way to aggregate groups.aggregateThe Median Operation— an overview of allmedianmodes.
For more information: See "groupBy statistics" on the documentation website., and See "GroupBy Aggregation Statistics" on the documentation website.
Example
// For each city, the median "age" and the median "weight"
df.groupBy { city }.medianFor { age and weight }Return
A new DataFrame with the group keys and the median of each selected column per group.
Parameters
The ColumnsForAggregateSelector used to select the columns to compute the median of.
Aggregates this GroupBy by computing the median of the values of each selected column separately, per group.
Returns a new DataFrame with one row per group, containing the group key columns and a column with the median for each selected 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.
For primitive numbers, the resulting median 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 median 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 "median Type Conversion" on the documentation website.
Result cells for which there is nothing to compute the median of (for instance, because the input was empty or contained only null values) simply become null.
See Selecting Columns.
See also:
median()— the same, but for all suitable columns at once.median{ columns }— a single median of all values in the selected columns, per group.— the general way to aggregate groups.aggregateThe Median Operation— an overview of allmedianmodes.
For more information: See "groupBy statistics" on the documentation website., and See "GroupBy Aggregation Statistics" on the documentation website.
Example
// For each city, the median "age" and the median "weight"
df.groupBy { city }.medianFor("age", "weight")Return
A new DataFrame with the group keys and the median of each selected column per group.
Parameters
The names of the columns to compute the median of. These must be existing columns holding self-comparable values, else an IllegalStateException is thrown.
Aggregates this Pivot by computing the median of the values of each selected column separately, per group.
Returns a single DataRow with the pivot keys as (nested) columns, containing the median of each selected column of the corresponding group.
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 median 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 median 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 "median Type Conversion" on the documentation website.
Result cells for which there is nothing to compute the median of (for instance, because the input was empty or contained only null values) simply become null.
The columns are selected with the ColumnsForAggregateSelectionDsl — an extension of the Columns Selection DSL which lets you rename the result of a column with and supply a into value for columns without any values.default
See Selecting Columns, or check out the .Pivot Grammar
See also:
median()— the same, but for all suitable columns at once.median{ columns }— a single median of all values in the selected columns, per group.Pivot aggregation— all other ways to aggregate aPivot.The Median Operation— an overview of allmedianmodes.
For more information: See "pivot statistics" on the documentation website., and See "Pivot Aggregation statistics" on the documentation website.
Example
// For each city, the median "age" and the median "weight"
df.pivot { city }.medianFor { age and weight }
// The same, but with the results grouped by aggregated column instead of by city
df.pivot { city }.medianFor(separate = true) { age and weight }Return
A single DataRow with the median of each selected column per pivot group.
Parameters
If false (the default), the resulting columns are indexed first by the pivot key(s) and then by the names of the aggregated columns. If true, this order is reversed: the results are grouped by aggregated column first.
The ColumnsForAggregateSelector used to select the columns to compute the median of.
Aggregates this Pivot by computing the median of the values of each selected column separately, per group.
Returns a single DataRow with the pivot keys as (nested) columns, containing the median of each selected column of the corresponding group.
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 median 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 median 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 "median Type Conversion" on the documentation website.
Result cells for which there is nothing to compute the median of (for instance, because the input was empty or contained only null values) simply become null.
See Selecting Columns, or check out the .Pivot Grammar
See also:
median()— the same, but for all suitable columns at once.median{ columns }— a single median of all values in the selected columns, per group.Pivot aggregation— all other ways to aggregate aPivot.The Median Operation— an overview of allmedianmodes.
For more information: See "pivot statistics" on the documentation website., and See "Pivot Aggregation statistics" on the documentation website.
Example
// For each city, the median "age" and the median "weight"
df.pivot { city }.medianFor("age", "weight")Return
A single DataRow with the median of each selected column per pivot group.
Parameters
The names of the columns to compute the median of. These must be existing columns holding self-comparable values, else an IllegalStateException is thrown.
If false (the default), the resulting columns are indexed first by the pivot key(s) and then by the names of the aggregated columns. If true, this order is reversed: the results are grouped by aggregated column first.
Aggregates this PivotGroupBy by computing the median of the values of each selected column separately, per group.
Returns a DataFrame where each cell contains the median of each selected column of the group corresponding to that pivot key (column) and groupBy key (row).
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 median 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 median 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 "median Type Conversion" on the documentation website.
Result cells for which there exists a group, but there is nothing to compute the median 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.
The columns are selected with the ColumnsForAggregateSelectionDsl — an extension of the Columns Selection DSL which lets you rename the result of a column with and supply a into value for columns without any values.default
See Selecting Columns, or check out the .PivotGroupBy Grammar
See also:
median()— the same, but for all suitable columns at once.median{ columns }— a single median of all values in the selected columns, per group.PivotGroupBy aggregation— all other ways to aggregate aPivotGroupBy.The Median Operation— an overview of allmedianmodes.
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 median "age" and the median "weight"
df.pivot { city }.groupBy { name.lastName }.medianFor { age and weight }Return
A DataFrame with the median of each selected column per pivot and groupBy group.
Parameters
If false (the default), the resulting columns are indexed first by the pivot key(s) and then by the names of the aggregated columns. If true, this order is reversed: the results are grouped by aggregated column first.
The ColumnsForAggregateSelector used to select the columns to compute the median of.
Aggregates this PivotGroupBy by computing the median of the values of each selected column separately, per group.
Returns a DataFrame where each cell contains the median of each selected column of the group corresponding to that pivot key (column) and groupBy key (row).
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 median 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 median 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 "median Type Conversion" on the documentation website.
Result cells for which there exists a group, but there is nothing to compute the median 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.
See Selecting Columns, or check out the .PivotGroupBy Grammar
See also:
median()— the same, but for all suitable columns at once.median{ columns }— a single median of all values in the selected columns, per group.PivotGroupBy aggregation— all other ways to aggregate aPivotGroupBy.The Median Operation— an overview of allmedianmodes.
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 median "age" and the median "weight"
df.pivot { city }.groupBy { name.lastName }.medianFor("age", "weight")Return
A DataFrame with the median of each selected column per pivot and groupBy group.
Parameters
The names of the columns to compute the median of. These must be existing columns holding self-comparable values, else an IllegalStateException is thrown.
If false (the default), the resulting columns are indexed first by the pivot key(s) and then by the names of the aggregated columns. If true, this order is reversed: the results are grouped by aggregated column first.
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html