Python
All Top Python 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: df
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
Starting the real Python + pandas runtime (one-time download)…