Clean and Analyze User Transactions with Python Functions
Company: PayPal
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates proficiency in data manipulation and feature engineering with Python and pandas, specifically cleaning transactional logs and deriving user-level time-based metrics such as inter-event intervals.
Filter user-months by volume
Tables
transactions(user_id INTEGER, trans_ts TIMESTAMP, amount DECIMAL(10,2))
Hints
- COUNT per user and calendar month using date_trunc('month', trans_ts).
- Join the monthly counts back to the base table and filter by count >= 100.
Average inter-transaction seconds
Tables
transactions(user_id INTEGER, trans_ts TIMESTAMP, amount DECIMAL(10,2))
Hints
- Use LAG to get the previous timestamp per user.
- Convert intervals to seconds with EXTRACT(EPOCH FROM ...), then average.