pyarrow.TableGroupBy

class pyarrow.TableGroupBy(table, keys)

Bases: object

A grouping of columns in a table on which to perform aggregations.

Parameters
tablepyarrow.Table

Input table to execute the aggregation on.

keysstr or list[str]

Name of the grouped columns.

__init__(self, table, keys)

Methods

__init__(self, table, keys)

aggregate(self, aggregations)

Perform an aggregation over the grouped columns of the table.

aggregate(self, aggregations)

Perform an aggregation over the grouped columns of the table.

Parameters
aggregationslist[tuple(str, str)] or list[tuple(str, str, FunctionOptions)]

List of tuples made of aggregation column names followed by function names and optionally aggregation function options.

Returns
Table

Results of the aggregation functions.

Examples

>>> t = pa.table([
...       pa.array(["a", "a", "b", "b", "c"]),
...       pa.array([1, 2, 3, 4, 5]),
... ], names=["keys", "values"])
>>> t.group_by("keys").aggregate([("values", "sum")])
pyarrow.Table
values_sum: int64
keys: string
----
values_sum: [[3,7,5]]
keys: [["a","b","c"]]