Skip to content

key: Union[StrictInt, StrictFloat, StrictStr, bool, Feature],
descending: bool=False
) -> Feature


Computes the rank of a specific key in the Cross Aggregate feature. If there are multiple keys with the same value, those keys will have the same rank, which equals the smallest rank among those keys. The key that is used for looking up the rank may either be a lookup feature or a scalar value.


  • key: Union[StrictInt, StrictFloat, StrictStr, bool, Feature]
    Key to lookup the value for.

  • descending: bool
    default: False
    Defaults to ranking in ascending order. Set to true to rank in descending order.


  • Feature
    A new Feature object.


Create a new feature by computing the rank for a particular key:

>>> counts = catalog.get_feature("CustomerProductGroupCounts_7d")
>>> new_feature ="Chips et Tortillas")
>>> = "Chips et Tortillas Rank"
Preview the features:

>>> features = fb.FeatureGroup([counts, new_feature])
>>> df = features.preview(pd.DataFrame([{"POINT_IN_TIME": "2022-04-15 10:00:00", "GROCERYCUSTOMERGUID": "2f4c1578-29d6-44b7-83da-7c5bfb981fa0"}]))
Dictionary feature:

>>> df["CustomerProductGroupCounts_7d"].iloc[0]
'{"Chips et Tortillas":1,"Colas, Thés glacés et Sodas":3,"Crèmes et Chantilly":1,"Pains":1,"Œufs":1}'

New feature:

>>> df["Chips et Tortillas Rank"].iloc[0]