Reducers

Usage

Reducers are used in reduce to compute the aggregated results obtained by a groupby:

my_table.groupby(table.columnA).reduce(aggregated_result=pw.reducers.my_reducer(my_table.columnB))

We use the following table t in the examples:

    colA  colB
1   valA   -1
2   valA    1
3   valA    2

List of Available Reducers

min

Returns the minimum of the aggregated values, throws an error if the table is empty.

t.groupby(t.colA).reduce(min=pw.reducers.min(t.colB))
            | min
^K8F4PWT... | -1

max

Returns the maximum of the aggregated values, throws an error if the table is empty.

t.groupby(t.colA).reduce(max=pw.reducers.max(t.colB))
            | max
^K8F4PWT... | 2

sum

Returns the sum of the aggregated values.

t.groupby(t.colA).reduce(sum=pw.reducers.sum(t.colB))
            | sum
^K8F4PWT... | 2

npsum

Return the sum of the values of aggregated numpy arrays.

t.groupby(t.colA).reduce(sum=pw.reducers.npsum(t.colB))
            | sum
^K8F4PWT... | 2

sorted_tuple

Return a sorted tuple containing all the aggregated values.

t.groupby(t.colA).reduce(tuples=pw.reducers.sorted_tuple(t.colB))
            | tuples
^K8F4PWT... | (-1, 1, 2)

count

Returning the number of aggregated elements.

t.groupby(t.colA).reduce(count=pw.reducers.count())
            | count
^K8F4PWT... | 3

argmin

Returns the index of the minimum aggregated value, returns None if the table is empty.

t.groupby(t.colA).reduce(argmin=pw.reducers.argmin(t.colB))
            | argmin
^K8F4PWT... | ^2TMTFGY...

argmax

Returns the index of the maximum aggregated value, returns None if the table is empty.

t.groupby(t.colA).reduce(argmax=pw.reducers.argmax(t.colB))
            | argmax
^K8F4PWT... | ^SERVYWW...