Python
All Top 50 Python & Pandas Interview Questions#43
Calculate Rolling 30-Day Moving Averages in Pandas
MediumFlipkartInterview Question #43
Asked at FlipkartGiven a daily sales DataFrame with a DatetimeIndex and `revenue`, compute a 30-day rolling mean `rolling_mean_30d` and rolling standard deviation `rolling_std_30d`.
Input Table: daily_revenue
2 rows preview| date | revenue |
|---|---|
| 2026-01-01 | 10000 |
| 2026-01-02 | 12000 |
Expected Output Structure1 rows
| date | revenue | rolling_mean_30d |
|---|---|---|
| 2026-01-30 | 11500 | 11200.5 |
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.