featurebyte.view.GroupBy.forward_aggregate¶
forward_aggregate(
value_column: Optional[str],
method: Union[AggFunc, str],
window: str,
target_name: str,
fill_value: Union[bool, int, float, str, NoneType]=None,
skip_fill_na: Optional[bool]=None,
offset: Optional[str]=None
) -> TargetDescription¶
The forward_aggregate method of a GroupBy class instance returns a Forward Aggregated Target object. This object aggregates data from the column specified by the value_column parameter using the aggregation method provided by the method parameter, without taking into account the order or sequence of the data. The primary entity of the Target is determined by the grouping key of the GroupBy instance.
Parameters¶
- value_column: Optional[str]
Column to be aggregated - method: Union[AggFunc, str]
Aggregation method. - window: str
Window size. Format of a window size is "{size}{unit}", where size is a positive integer and unit is one of the following:
"ns": nanosecond
"us": microsecond
"ms": millisecond
"s": second
"m": minute
"h": hour
"d": day
"w": week - target_name: str
Output target name - fill_value: Union[bool, int, float, str, NoneType]
Value to fill if the value in the column is empty - skip_fill_na: Optional[bool]
Whether to skip filling NaN values, filling nan operation is skipped by default as it is expensive during feature serving - offset: Optional[str]
Offset duration to apply to the window, such as '1d'. If specified, the windows will be shifted forward by the offset duration
Returns¶
- Target
Examples¶
>>> items_view = catalog.get_view("INVOICEITEMS")
>>> # Group items by the column GroceryInvoiceGuid that references the customer entity
>>> items_by_invoice = items_view.groupby("GroceryInvoiceGuid")
>>> # Get the number of items in each invoice
>>> invoice_item_count = items_by_invoice.forward_aggregate(
... "TotalCost",
... method=fb.AggFunc.SUM,
... target_name="TargetCustomerInventory_28d",
... window="28d",
... )