--- title: Session keywords: fastai sidebar: home_sidebar summary: "Create sessions." description: "Create sessions." nb_path: "nbs/transforms/transforms.session.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}

#### `construct_session_sequences`[source]

> `construct_session_sequences`(`df`, `sessionID`, `itemID`)

Given a dataset in pandas df format, construct a list of lists where each sublist represents the interactions relevant to a specific session, for each sessionID. These sublists are composed of a series of itemIDs (str) and are the core training data used in the Word2Vec algorithm. This is performed by first grouping over the SessionID column, then casting to list each group's series of values in the ItemID column.

## INPUTS

df: pandas dataframe sessionID: str column name in the df that represents invididual sessions itemID: str column name in the df that represents the items within a session

{% endraw %} {% raw %}
{% endraw %} {% raw %}

    import pandas as pd

    df = pd.DataFrame.from_dict({
        'SessionID':[1,1,1,2,2,2,2,2],
        'ItemID':[111,123,345,45,334,342,8970,345]
    })
    df

| SessionID | ItemID
--- | --- | ---
0 | 1 | 111
1 | 1 | 123
2 | 1 | 345
3 | 2 | 45
4 | 2 | 334
5 | 2 | 342
6 | 2 | 8970
7 | 2 | 345

{% endraw %} {% raw %}

    construct_session_sequences(df, sessionID='SessionID', itemID='ItemID')

    [[111, 123, 345], [45, 334, 342, 8970, 345]]

{% endraw %}