Sessionize App Events Into an Ordered Search to Purchase Funnel
Last updated: November 29, 2026
Quick Overview
Given a pandas DataFrame of app events (user_id, ts, event), split each user's events into sessions using a 30-minute inactivity gap and compute how many sessions reach search, product view, add to cart and purchase in that order.
Flipkart
November 29, 20260
0
0 solved
Given a pandas DataFrame of app events (user_id, ts, event), split each user's events into sessions using a 30-minute inactivity gap and compute how many sessions reach search, product view, add to cart and purchase in that order.
Flipkart product analytics relies on session funnels to see where shoppers drop between search and purchase on the app. A pandas exercise like this checks whether you can sessionize with groupby and diff, enforce stage order rather than counting any occurrence, and avoid subtle mistakes like filtering events before sessionizing.
What the Interviewer Expects
- Sort by user and time and compute per-user time gaps
- Start a new session on the first event or a gap over 30 minutes
- Sessionize on all events before filtering to funnel events
- Enforce ordered stages within a session
- Report per-stage counts with step and overall conversion
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you vectorize the ordered-stage logic for 500 million events?
- Should a purchase be credited to the search session if the user bought in a new session 40 minutes later?
- How would you compute the same funnel in SQL?
- How do you handle events with identical timestamps?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Columns: user_id, ts (datetime), event (search, product_view, add_to_cart, purchase, plus others such as wishlist). Session break: more than 30 minutes since the user's previous event of any kin...
Approach
- Sort by user and time,
groupby(user).diff()for gaps, flag new sessions, cumulative sum per user for a session number. - Filter to funnel events only after sessions are assigned, so non-funnel a...