Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Master Data Science with Python

Lesson 27 of 60 · python

Time Series Data with Pandas

Duration: 25 minutes

Time Series with Pandas

Temporal data analysis is a core skill for finance, IoT, and many domains.

Converting strings to datetime

df['date'] = pd.to_datetime(df['date'])

Setting the datetime index

df_ts = df.set_index('date')
print(df_ts.head())

Resampling (e.g., daily to monthly)

monthly = df_ts.resample('M').sum()
print(monthly.head())

Rolling windows

# 7‑day moving average of a metric
df_ts['metric_ma7'] = df_ts['metric'].rolling(window=7).mean()

Time‑zone handling

df['date_utc'] = df['date'].dt.tz_localize('UTC')
df['date_est'] = df['date_utc'].dt.tz_convert('US/Eastern')

Frequency conversion and forward/backward fill

# Forward fill missing daily data
filled = df_ts.asfreq('D', method='ffill')

Info

Pandas leverages numpy.datetime64 under the hood, making date arithmetic fast.

Previous: Pivot Tables and CrosstabulationsNext: Categorical Data and Encoding Techniques