MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Resampling, Rolling Windows & Shifting0%
Study MaterialsCheatsheet
PandasProgress 0%
1.1What is Pandas & Core Architecture1.2Pandas Installation & Environment Setup1.3Creating Series & DataFrames from Scratch
8.1DateTime Parsing, Indexing & .dt Accessor8.2Resampling, Rolling Windows & Shifting8.3End-to-End Exploratory Data Analysis (EDA) Project
HomeTutorialsPandasResampling, Rolling Windows & Shifting
End-to-End Exploratory Data Analysis (EDA) Project

Resampling, Rolling Windows & Shifting

Intermediate6 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. Time-Series Frequency Conversions (resample)

resample() is essentially a groupby() operation specifically for time-series data. It groups timestamps into discrete intervals (e.g., daily data into weekly, monthly, or quarterly summaries):

1import pandas as pd
2import numpy as np
3 
4# Create daily sales data for 90 days
5dates = pd.date_range(start='2026-01-01', periods=90, freq='D')
6df = pd.DataFrame({
7 'Daily_Sales': np.random.randint(10000, 50000, size=90)
8}, index=dates)
9 
10# Resample from Daily to Monthly Sums ('ME' = Month End)
11monthly_sales = df.resample('ME').sum()
12print("Monthly Revenue:\n", monthly_sales)

2. Rolling Window Calculations (Moving Averages)

In financial markets and business forecasting, daily metrics fluctuate wildly. A Rolling Moving Average smooths out noise to reveal underlying trends:

1# 7-Day Moving Average of Sales
2df['7_Day_MA'] = df['Daily_Sales'].rolling(window=7).mean()
3 
4# 30-Day Rolling Standard Deviation (Volatility)
5df['30_Day_Volatility'] = df['Daily_Sales'].rolling(window=30).std()
6print(df.tail(10))

3. Shifting Data for Period-over-Period Growth (.shift)

To compute Day-over-Day or Month-over-Month growth, compare today's sales with yesterday's sales by shifting values down:

1# Shift values down by 1 row (yesterday's sales)
2df['Prev_Day_Sales'] = df['Daily_Sales'].shift(1)
3 
4# Calculate Day-over-Day percentage change
5df['DoD_Growth_Pct'] = (
6 (df['Daily_Sales'] - df['Prev_Day_Sales']) / df['Prev_Day_Sales']
7) * 100
8 
9# Or use the built-in shortcut:
10df['DoD_Growth_Shortcut'] = df['Daily_Sales'].pct_change() * 100

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Which method performs time-based frequency aggregation (e.g. converting hourly or daily records into monthly summaries)?
Question 2
What does df['Sales'].rolling(window=7).mean() calculate?
Question 3
What does Series.shift(1) do?
Question 4
Which built-in Pandas method directly computes the percentage change between the current and previous element?
Question 5
In modern Pandas, what frequency alias represents Month End in resample()?

Next Lesson

End-to-End Exploratory Data Analysis (EDA) Project

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
DateTime Parsing, Indexing & .dt AccessorEnd-to-End Exploratory Data Analysis (EDA) Project

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

12-Month Data Analysis Mastery Program

Master Full-Stack Data Analytics (Excel, SQL, Python, Power BI & Tableau)

Combine 15 complete courses, 150 chapters, 541 topics, live SQL/Power BI/Tableau dashboards, and Scikit-Learn capstones at MSK Institute Shikohabad or Live Online.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext