pandas: top-N per group and leakage-safe rolling features
Interview insights are lockedSee how often this is asked and which companies asked it with Buncho Pro.A DataFrame df has columns user_id, ts (datetime) and amount. Write code to produce:
- the 3 largest transactions per user,
- a feature
avg_7d: each user's meanamountover the previous 7 days, excluding the current row, - a feature
days_since_prev: days since that user's previous transaction.
Explain why (2) must exclude the current row.