sumFor
Returns the sum of the values of each selected column of this DataFrame separately.
All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (, BigInteger) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
Result cells for which there is nothing to sum (for instance, because the input was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).
For more information about the resulting types: See "sum Type Conversion" on the documentation website. 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
This can include column groups and nested columns.
See Selecting Columns.
See also:
sum()— the same, but for all suitable columns at once.sum{ columns }— a single sum of all values in the selected columns.— the sum of each selected column divided by its number of values.meanForThe Sum Operation— an overview of allsummodes.
For more information: See sum on the documentation website.
Example
// A single row with the sum of the "age" values and the sum of the "weight" values
df.sumFor { age and weight }
// The same, ignoring `NaN` values, and naming the results explicitly
df.sumFor(skipNaN = true) { age into "totalAge" and (weight into "totalWeight") }Return
A single DataRow with the sum of each selected column.
Parameters
The ColumnsForAggregateSelector used to select the columns to compute the sum of.
Returns the sum of the values of each selected column of this DataFrame separately.
All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (, BigInteger) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
Result cells for which there is nothing to sum (for instance, because the input was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
This can include column groups and nested columns.
See Selecting Columns.
See also:
sum()— the same, but for all suitable columns at once.sum{ columns }— a single sum of all values in the selected columns.— the sum of each selected column divided by its number of values.meanForThe Sum Operation— an overview of allsummodes.
For more information: See sum on the documentation website.
Example
// A single row with the sum of the "age" values and the sum of the "weight" values
df.sumFor("age", "weight")Return
A single DataRow with the sum of each selected column.
Parameters
The names of the columns to compute the sum of. These must be existing primitive number columns, else an IllegalStateException or IllegalArgumentException is thrown.
Aggregates this GroupBy by computing the sum 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 sum for each selected column.
All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (, BigInteger) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
Result cells for which there is nothing to sum (for instance, because the input was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).
For more information about the resulting types: See "sum Type Conversion" on the documentation website. 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
This can include column groups and nested columns.
See Selecting Columns.
See also:
sum()— the same, but for all suitable columns at once.sum{ columns }— a single sum of all values in the selected columns, per group.— the sum of each selected column divided by its number of values, per group.meanFor— the general way to aggregate groups.aggregateThe Sum Operation— an overview of allsummodes.
For more information: See "groupBy statistics" on the documentation website., and See "GroupBy Aggregation Statistics" on the documentation website.
Example
// For each city, the sum of the "age" values and the sum of the "weight" values
df.groupBy { city }.sumFor { age and weight }Return
A new DataFrame with the group keys and the sum of each selected column per group.
Parameters
The ColumnsForAggregateSelector used to select the columns to compute the sum of.
Aggregates this GroupBy by computing the sum 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 sum for each selected column.
All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (, BigInteger) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
Result cells for which there is nothing to sum (for instance, because the input was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
This can include column groups and nested columns.
See Selecting Columns.
See also:
sum()— the same, but for all suitable columns at once.sum{ columns }— a single sum of all values in the selected columns, per group.— the sum of each selected column divided by its number of values, per group.meanFor— the general way to aggregate groups.aggregateThe Sum Operation— an overview of allsummodes.
For more information: See "groupBy statistics" on the documentation website., and See "GroupBy Aggregation Statistics" on the documentation website.
Example
// For each city, the sum of the "age" values and the sum of the "weight" values
df.groupBy { city }.sumFor("age", "weight")Return
A new DataFrame with the group keys and the sum of each selected column per group.
Parameters
The names of the columns to compute the sum of. These must be existing primitive number columns, else an IllegalStateException or IllegalArgumentException is thrown.
Aggregates this Pivot by computing the sum of the values of each selected column separately, per group.
Returns a single DataRow with the pivot keys as (nested) columns, containing the sum of each selected column of the corresponding group.
All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (, BigInteger) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
Result cells for which there is nothing to sum (for instance, because the input was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).
For more information about the resulting types: See "sum Type Conversion" on the documentation website. 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
This can include column groups and nested columns.
See Selecting Columns, or check out the .Pivot Grammar
See also:
sum()— the same, but for all suitable columns at once.sum{ columns }— a single sum of all values in the selected columns, per group.Pivot aggregation— all other ways to aggregate aPivot.The Sum Operation— an overview of allsummodes.
For more information: See "pivot statistics" on the documentation website., and See "Pivot Aggregation statistics" on the documentation website.
Example
// For each city, the sum of the "age" values and the sum of the "weight" values
df.pivot { city }.sumFor { age and weight }
// The same, but with the results grouped by aggregated column instead of by city
df.pivot { city }.sumFor(separate = true) { age and weight }Return
A single DataRow with the sum 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 sum of.
Aggregates this Pivot by computing the sum of the values of each selected column separately, per group.
Returns a single DataRow with the pivot keys as (nested) columns, containing the sum of each selected column of the corresponding group.
All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (, BigInteger) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
Result cells for which there is nothing to sum (for instance, because the input was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
This can include column groups and nested columns.
See Selecting Columns, or check out the .Pivot Grammar
See also:
sum()— the same, but for all suitable columns at once.sum{ columns }— a single sum of all values in the selected columns, per group.Pivot aggregation— all other ways to aggregate aPivot.The Sum Operation— an overview of allsummodes.
For more information: See "pivot statistics" on the documentation website., and See "Pivot Aggregation statistics" on the documentation website.
Example
// For each city, the sum of the "age" values and the sum of the "weight" values
df.pivot { city }.sumFor("age", "weight")Return
A single DataRow with the sum of each selected column per pivot group.
Parameters
The names of the columns to compute the sum of. These must be existing primitive number columns, else an IllegalStateException or IllegalArgumentException 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 sum of the values of each selected column separately, per group.
Returns a DataFrame where each cell contains the sum of each selected column of the group corresponding to that pivot key (column) and groupBy key (row).
All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (, BigInteger) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
Result cells for which there exists a group, but there is nothing to sum (for instance, because the group was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
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
This can include column groups and nested columns.
See Selecting Columns, or check out the .PivotGroupBy Grammar
See also:
sum()— the same, but for all suitable columns at once.sum{ columns }— a single sum of all values in the selected columns, per group.PivotGroupBy aggregation— all other ways to aggregate aPivotGroupBy.The Sum Operation— an overview of allsummodes.
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 sum of the "age" values and the sum of the "weight" values
df.pivot { city }.groupBy { name.lastName }.sumFor { age and weight }Return
A DataFrame with the sum of each selected column per 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 sum of.
Aggregates this PivotGroupBy by computing the sum of the values of each selected column separately, per group.
Returns a DataFrame where each cell contains the sum of each selected column of the group corresponding to that pivot key (column) and groupBy key (row).
All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (, BigInteger) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, unless skipNaN is set to true.
The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
Result cells for which there exists a group, but there is nothing to sum (for instance, because the group was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).
For more information about the resulting types: See "sum Type Conversion" on the documentation website.
For empty pivot intersections, null or the set default is used.
This can include column groups and nested columns.
See Selecting Columns, or check out the .PivotGroupBy Grammar
See also:
sum()— the same, but for all suitable columns at once.sum{ columns }— a single sum of all values in the selected columns, per group.PivotGroupBy aggregation— all other ways to aggregate aPivotGroupBy.The Sum Operation— an overview of allsummodes.
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 sum of the "age" values and the sum of the "weight" values
df.pivot { city }.groupBy { name.lastName }.sumFor("age", "weight")Return
A DataFrame with the sum of each selected column per group.
Parameters
The names of the columns to compute the sum of. These must be existing primitive number columns, else an IllegalStateException or IllegalArgumentException 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