A session identifier distinguishes one user session from another in app-event data. Combined with user ID, it lets analysis count sessions and connect events to session-level activity. section 12.5.1
A practical workflow uses the identifier to:
- Check missing values and convert session ID to an explicit integer type. section 12.5.1
- Count unique sessions per user with pandas groupby and nunique operations. section 12.5.1
- Group by user ID and session ID to derive each session’s start, end, and duration. section 12.5.1
Deriving session duration
Group events by user ID and session ID, take the minimum and maximum timestamps, and calculate the elapsed time in minutes. section 12.5.1
import pandas as pd
import matplotlib.pyplot as plt
app_data = pd.read_csv(
"./data/lsapp.tsv.gz",
sep="\t", #1
names=["user_id", "session_id", "timestamp",
"app_name", "event_type"], #2
parse_dates=["timestamp"], #3
skiprows=1 #4
)
print(app_data.shape)
app_data.head()
Inspect the event schema containing user ID, session ID, timestamp, app name, and event type. section 12.5.1
