Data structures required to use PyWIB

The library operates on a pandas.DataFrame in which each row represents a single interaction event. This page describes the expected columns and shows an example of a valid input.

Required columns

Every DataFrame must contain the following columns. Missing any of them will raise an error at validation time.

Column

Type

Description

sessionId

str

Identifier of the session the event belongs to.

x

float

Horizontal coordinate of the event.

y

float

Vertical coordinate of the event.

timeStamp

int

Time at which the event occurred in milliseconds.

eventType

str

Type of the event as a number identified by one of the EventTypes.

Optional columns

The following columns are optional. If present, they enable additional functionality; if absent, the library falls back to default behavior.

Column

Type

Description

keyValue

str

Value of the key associated with a keyboard event.

keyCode

str

Code of the key associated with a keyboard event.

sourceSessionId

str

Identifier of the session from which this session originates.

elementId

str

Identifier of the UI element targeted by the event.

sceneId

str

Identifier of the scene in which the event took place.

Note

Column names are case-sensitive and must match exactly as written above.

In case of doubt, please use values from the class ColumnNames.

from pywib import ColumnNames

print(ColumnNames.SESSION_ID)  # prints "sessionId"

Example

The following DataFrame contains the required columns plus a few optional ones:

import pandas as pd
from pywib import ColumnNames

df = pd.DataFrame({
    ColumnNames.SESSION_ID: ["s1", "s1", "s1", "s2"],
    ColumnNames.X:         [120.0, 245.5, 245.5, 30.0],
    ColumnNames.Y:         [80.0, 310.2, 310.2, 415.0],
    ColumnNames.TIME_STAMP: [1700000000, 1700000002, 1700000003, 1700000100],
    ColumnNames.EVENT_TYPE: [0, 0, 13, 1],
    ColumnNames.KEY_VALUE":  [-1, -1, "a", -1],
    ColumnNames.KEY_CODE:   [-1, -1, "KeyA", -1],
    ColumnNames.ELEMENT_ID: [-1, -1, "input-name", "btn-exit"],
    ColumnNames.SCENE_ID:   ["intro", "intro", "intro", "outro"],
})

Which renders as:

sessionId

x

y

timeStamp

eventType

keyValue

keyCode

elementId

sceneId

s1

120.0

80.0

1700000000

0

btn-start

intro

s1

245.5

310.2

1700000002

0”

intro

s1

245.5

310.2

1700000003

13

a

KeyA

input-name

form

s2

30.0

415.0

1700000100

1

btn-exit

outro

Note

A function that renames columns has been created to ease working with this format.

See to_pywib_df()

Minimal example

A DataFrame with only the required columns is also valid:

 from pywib import to_pywib_df

 df_minimal = pd.DataFrame({
    "id": ["s1", "s1"],
    "xPos":         [10.0, 20.0],
    "yPos":         [15.0, 25.0],
    "timeStamp": [1700000000, 1700000001],
    "event": [1, 1],
})
df_minimal = to_pywib_df(df_minimal, "id", "xPos", "yPos", "timeStamp","event")