Skip to content

Aggregates

Typed aggregate functions for use with the typed DataFrame constructor.

Pass aggregate columns alongside .group() columns when constructing a typed DataFrame — see DataFrame for usage.

Implemented

count, count_distinct, count_if, countDistinct, approx_count_distinct, sum / sum_distinct / sumDistinct (integral → Long, Float/Double → Double), avg, mean, stddev, stddev_samp, stddev_pop, corr, covar_pop, covar_samp, collect_list, collect_set, min, max, min_by, max_by, first, last

Not yet implemented (contributions welcome)

variance / var_samp / var_pop — Column → Double kurtosis — Column → Double skewness — Column → Double median — Column → Double mode — Column → C percentile_approx — (Column, percentage, accuracy) → Double bit_and / bit_or / bit_xor — C → C (integer columns) nth_value — (C, offset) → C any_value — C → C

sumDistinct module-attribute

sumDistinct = sum_distinct

mean module-attribute

mean = avg

min

min(col: C) -> C

max

max(col: C) -> C

first

first(col: C, ignorenulls: bool = False) -> C

last

last(col: C, ignorenulls: bool = False) -> C

min_by

min_by(col: C, ord: Column) -> C

max_by

max_by(col: C, ord: Column) -> C

count

count(col: Column) -> Long

countDistinct

countDistinct(*cols: Column) -> Long

approx_count_distinct

approx_count_distinct(
    col: Column, rsd: float = 0.05
) -> Long

count_distinct

count_distinct(*cols: Column) -> Long

count_if

count_if(col: Bool) -> Long

sum

sum(col: Short | Integer | Long) -> Long
sum(col: Float | Double) -> Double
sum(col: C) -> C
sum(col: Column) -> Column

sum_distinct

sum_distinct(col: Short | Integer | Long) -> Long
sum_distinct(col: Float | Double) -> Double
sum_distinct(col: C) -> C
sum_distinct(col: Column) -> Column

avg

avg(col: Column) -> Double

stddev

stddev(col: Column) -> Double

stddev_samp

stddev_samp(col: Column) -> Double

stddev_pop

stddev_pop(col: Column) -> Double

corr

corr(col1: Column, col2: Column) -> Double

covar_pop

covar_pop(col1: Column, col2: Column) -> Double

covar_samp

covar_samp(col1: Column, col2: Column) -> Double

collect_list

collect_list(col: C) -> Array[C]

Aggregates values of col into an array, preserving duplicates and order.

Wrapper for pyspark.sql.functions.collect_list.

collect_set

collect_set(col: C) -> Array[C]

Aggregates unique values of col into an array.

Wrapper for pyspark.sql.functions.collect_set.