Python
#43

Calculate Rolling 30-Day Moving Averages in Pandas

MediumFlipkart
Interview Question #43
Asked at Flipkart

Given 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: df
10 rows preview
daterevenue
2026-01-0110000
2026-01-0212000
2026-01-0311000
2026-01-0413000
2026-01-059500
2026-01-0610500
2026-01-0711500
2026-01-0812500
2026-01-0910800
2026-01-1011200
Expected Output Structure10 rows
daterevenuerolling_mean_30drolling_std_30d
2026-01-0110000NULLNULL
2026-01-0212000NULLNULL
2026-01-0311000NULLNULL
2026-01-0413000NULLNULL
2026-01-059500NULLNULL
2026-01-0610500NULLNULL
2026-01-071150011071.431205.15
2026-01-0812500112501224.74
2026-01-0910800112001155.42
2026-01-1011200112001089.34
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)…

Chat with us