Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Date and Time-Based Features | Section
Engineering Temporal Features

bookDate and Time-Based Features

Swipe to show menu

Extracting calendar-based features from date and time information is a powerful technique in temporal feature engineering. By breaking down a timestamp into components such as the day of the week, month, or whether it falls on a weekend, you can capture recurring patterns or seasonality that often drive changes in real-world data. These features are especially valuable in time series forecasting, where many phenomena – like sales, traffic, or energy usage – follow predictable cycles tied to the calendar. For example, demand might spike on weekends or drop during certain months, and models that incorporate this information can make more accurate predictions.

12345678910111213141516
import pandas as pd # Create a sample datetime index dates = pd.date_range(start="2024-06-01", end="2024-06-14", freq="D") df = pd.DataFrame(index=dates) # Extract day of week (Monday=0, Sunday=6) df["day_of_week"] = df.index.dayofweek # Extract month df["month"] = df.index.month # Determine if the date is a weekend (Saturday=5, Sunday=6) df["is_weekend"] = df.index.dayofweek >= 5 print(df)
copy
question mark

Why are calendar-based features, such as day of week or month, important when building time series forecasting models?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 6

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Section 1. Chapter 6
some-alt