get_context

rectools.dataset.context.get_context(df: DataFrame) DataFrame[source]

Extract initial interaction context for each user.

For each user, finds the earliest index base on datetime and uses it to define the initial contextual data. If the item column is present, it is dropped from the result, as it’s not part of the user context.

Parameters

df (pd.DataFrame) – Input DataFrame containing user interactions with at least user ID and datetime columns.

Returns

A DataFrame with one row per user, representing the earliest context data for that user.

Return type

pd.DataFrame