vastorbit.VastFrame.sessionize¶
- VastFrame.sessionize(ts: str, by: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, session_threshold: str = '30 minutes', name: str = 'session_id') VastFrame¶
Adds a new VastColumn to the VastFrame that corresponds to sessions (user activity during a specific time). A session ends when ts - lag(ts) is greater than a specific threshold.
- Parameters:
ts (str) – VastColumn used as timeline. It is used to order the data. It can be a numerical or type date (date, datetime, timestamp…) VastColumn.
by (SQLColumns, optional) – VastColumn used in the partition.
session_threshold (str, optional) – This parameter is the threshold that determines the end of the session. For example, if it is set to ‘10 minutes’, the session ends after 10 minutes of inactivity. Format: ‘10 minutes’, ‘30 seconds’, ‘1 hour’, etc.
name (str, optional) – The session name.
- Returns:
self
- Return type:
Examples
import vastorbit as vo vdf = vo.VastFrame({ "time": [ "1993-11-03 00:00:00", "1993-11-03 00:14:00", "1993-11-03 00:07:00", "1993-11-03 01:00:00", "1993-11-03 01:05:05", "1993-11-03 01:15:05", "1993-11-03 01:45:01", ], "val": [0., 1., 2., 4., 5., 5.5, 6.], }) vdf["time"].astype("timestamp") # Create sessions with 15 minute threshold vdf.sessionize( ts="time", session_threshold="15 minutes", )
Note
This method is particularly useful for clickstream analytics, enabling the creation of sessions as part of data preparation for machine learning.
See also
VastFrame.analytic(): Use an advanced analytical function on one or two specific VastColumn.