Python
All Top 50 Python & Pandas Interview Questions#47
Downsample and Aggregate Time Series with resample() in Pandas
MediumInterview Question #47
Given a high-frequency transaction log indexed by Datetime, downsample the data into calendar month-end buckets ('ME') and compute total monthly revenue and transaction count.
Input Table: txns
3 rows preview| timestamp | amount |
|---|---|
| 2026-01-05 10:00:00 | 500 |
| 2026-01-20 14:00:00 | 750 |
| 2026-02-02 09:00:00 | 1200 |
Expected Output Structure2 rows
| timestamp | total_revenue | txn_count |
|---|---|---|
| 2026-01-31 | 1250 | 2 |
| 2026-02-28 | 1200 | 1 |
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.