dataframe-0.7.0.0: A fast, safe, and intuitive DataFrame library.
Safe HaskellNone
LanguageHaskell2010

DataFrame.Typed.Aggregate

Synopsis

Typed groupBy

groupBy :: forall (keys :: [Symbol]) (cols :: [Type]). (AllKnownSymbol keys, AssertAllPresent keys cols) => TypedDataFrame cols -> TypedGrouped keys cols Source #

Group a typed DataFrame by one or more key columns.

grouped = groupBy @'["department"] employees

Typed aggregation builder (Option B)

agg :: forall (name :: Symbol) a (keys :: [Symbol]) (cols :: [Type]) (aggs :: [Type]). (KnownSymbol name, Columnable a) => TExpr cols a -> TAgg keys cols aggs -> TAgg keys cols (Column name a ': aggs) Source #

Add one aggregation to the builder.

Each call prepends a Column name a to the result schema and records the runtime NamedExpr. The expression is validated against the source schema cols at compile time.

agg @"total_sales" (tsum (col @"salary"))
  $ agg @"avg_price" (tmean (col @"price"))
  $ aggNil

aggNil :: forall (keys :: [Symbol]) (cols :: [Type]). TAgg keys cols ('[] :: [Type]) Source #

The empty aggregation — no output columns beyond the group keys.

Running aggregations

aggregate :: forall (keys :: [Symbol]) (cols :: [Type]) (aggs :: [Type]). TAgg keys cols aggs -> TypedGrouped keys cols -> TypedDataFrame (Append (GroupKeyColumns keys cols) (Reverse aggs)) Source #

Run a typed aggregation.

Result schema = grouping key columns ++ aggregated columns (in declaration order).

result = aggregate
    (agg @"total" (tsum (col "salary")) $ agg @"count" (tcount (col "salary") $ aggNil)
    (groupBy @'["dept"] employees)
-- result :: TDF '[Column "dept" Text, Column "total" Double, Column "count" Int]

Escape hatch

aggregateUntyped :: forall (keys :: [Symbol]) (cols :: [Type]). [NamedExpr] -> TypedGrouped keys cols -> DataFrame Source #

Escape hatch: run an untyped aggregation and return a raw DataFrame.