Python
All Top 50 Python & Pandas Interview Questions#23
Deduplicate DataFrames by Subset Columns in Pandas
EasyFlipkartInterview Question #23
Asked at FlipkartGiven an event log with `user_id`, `event_name`, and `timestamp`, remove duplicate user actions on the same event, keeping only the most recent occurrence (`keep='last'`).
Input Table: event_logs
3 rows preview| user_id | event_name | timestamp |
|---|---|---|
| 101 | add_to_cart | 2026-02-01 10:00:00 |
| 101 | add_to_cart | 2026-02-01 10:05:00 |
| 102 | add_to_cart | 2026-02-01 11:00:00 |
Expected Output Structure2 rows
| user_id | event_name | timestamp |
|---|---|---|
| 101 | add_to_cart | 2026-02-01 10:05:00 |
| 102 | add_to_cart | 2026-02-01 11:00:00 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
Python 3.10 (Pandas)
Environment Ready
Click "Run & Test" to execute your Pandas code against the test assertions.