featurebyte.EventView.add_feature¶
add_feature(
new_column_name: str,
feature: Feature,
entity_column: Optional[str]=None
) -> EventViewDescription¶
Adds a simple aggregate feature obtained from an Item View to the corresponding Event View. Once the feature is integrated in this manner, it can be aggregated as any other column over a time frame to create Aggregate Over a Window features.
For example, one can calculate a customer's average order size over the last three weeks by using the order size feature extracted from the Order Items view and aggregating it over that time frame in the related Order view.
Parameters¶
- new_column_name: str
The new column name to be added to the EventView. - feature: Feature
The feature we want to add to the EventView. - entity_column: Optional[str]
The column representing the primary entity of the added feature in the EventView.
Returns¶
- EventView
The EventView with the new feature added.
Examples¶
Add feature to an EventView.
>>> 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.aggregate(
... None,
... method=fb.AggFunc.COUNT,
... feature_name="InvoiceItemCount",
... )