Generate Synthetic Clickstream Data with Python Function
AmazonData Scientist · Technical ScreenLast updated
This question evaluates a candidate's ability to implement synthetic data generation and probabilistic event simulation in Python using libraries like pandas and numpy, emphasizing timestamp handling, random sampling, and feature engineering for clickstream records.
Scenario
The analytics team needs to generate synthetic click-stream records to test a new reporting pipeline before real traffic arrives.
Question
Write a Python function simulate_clickstream(num_users: int, days: int) that returns a Pandas DataFrame of simulated events with columns [user_id, event_ts, page, clicked]. Events should be timestamped within the past <days> days, each user should visit 1–10 random pages per day, and click probability is 0.15.
Hints
Use numpy.random for page counts and probabilities; build a list of dicts, then convert to DataFrame.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.