Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric certified for FREE! Don't miss your chance! Learn more
There’s a moment in every data professional’s journey where the data looks right, the model runs smoothly, yet something feels missing. The predictions are just… off. You check your preprocessing steps, review your scaling, even tweak your hyperparameters, but the improvement barely moves the needle. That’s when you realize - the issue isn’t the algorithm, it’s the features. Specifically, it’s what you’ve failed to teach your model about time. Time has rhythm. It influences everything from when people shop and when they cancel subscriptions to when systems fail and when stock prices peak.
But in most datasets, time is trapped inside a column named timestamp... static, unexpressed, and underutilized. The reality is, timestamps are goldmines of hidden patterns, and unless you mine them properly, your model will always be partially blind to the world it’s trying to predict. When I work with teams on machine learning projects, I often see this mistake repeat itself: people ignore date and time. They think of it as metadata rather than data. But the reality is that when something happens is often as important as what happened. Understanding this distinction is the key to creating features that make your models both more accurate and more trustworthy.
What you will learn: In this edition, you’ll learn how to extract features like week, quarter, holiday, and season using Python with pandas, datetime, and the holidays library - all within Microsoft Fabric’s Notebooks. By the end, you’ll know exactly how to make time work for you, by teaching your data to understand patterns, rhythms, and real-world cycles. And because time features are often the hidden key to better predictions, we’ll go beyond the code to explore why each step truly matters.
Read Time: 8 minutes
Source: Sahir Maharaj (https://sahirmaharaj.com)
The first thing to understand about temporal features is that they reflect real human behavior. For example, think about how your own habits change throughout the week - Mondays might feel sluggish, Fridays energetic, and Sundays restful. These patterns don’t just exist in your personal life; they occur through sales data, web traffic logs, and service usage metrics across every industry. Extracting features like day of the week or hour of the day gives your models a sense of those natural rhythms.
In business forecasting, understanding time is often the difference between accurate predictions and misleading noise. A retail store might sell twice as much in December as in July, but unless your model understands why that happens (say, due to holiday shopping) it won’t anticipate it. That’s where temporal features step in. By encoding months, quarters, and holidays, you teach your model that “December” isn’t just a number but a special season filled with unique behaviors.
import pandas as pd
from datetime import datetime
data = {
'timestamp': [
'2024-01-15 10:30:00',
'2024-04-20 16:45:00',
'2024-07-10 09:20:00',
'2024-10-05 13:15:00',
'2024-12-25 18:00:00'
]
}
df = pd.DataFrame(data)
df['timestamp'] = pd.to_datetime(df['timestamp'])
df['year'] = df['timestamp'].dt.year
df['month'] = df['timestamp'].dt.month
df['day'] = df['timestamp'].dt.day
df['hour'] = df['timestamp'].dt.hour
df['day_of_week'] = df['timestamp'].dt.day_name()
df['week_of_year'] = df['timestamp'].dt.isocalendar().week
df['quarter'] = df['timestamp'].dt.quarter
df['is_weekend'] = df['day_of_week'].isin(['Saturday', 'Sunday'])
print(df.head())
Another example I like to often use is call center data. Without temporal features, you might assume that call volumes are evenly distributed. But add in a feature for “hour of day,” and suddenly you notice a sharp spike between 9 AM and noon. Add “day of week,” and you realize Mondays are overwhelming compared to Fridays. And the amazing thing is that, these insights aren’t just useful for models, but also guide business decisions like staff scheduling and resource allocation.
To work with date and time effectively, the pandas library is your best friend. It has built-in datetime accessors that can extract almost any aspect of a timestamp... from the hour and week number to whether a date falls on a Monday or a Friday. But before you can extract features, you first need to ensure your data is in the right format. Let’s start with something relatable - a list of event dates, like product orders, website signups, or customer visits. You can transform this list into a pandas DataFrame and begin exploring how to manipulate time-based data step by step. As a data scientist, I've learned that this gradual approach is so important because many readers rush to advanced features without first building a strong foundation.
Source: Sahir Maharaj (https://sahirmaharaj.com)
Now that you’ve got the timestamps in datetime format, the fun begins. Using pandas’ .dt accessor, you can extract several features directly. As you run this, you’ll notice how the dataset begins to evolve into something richer. What was once just a string of dates now tells a story. You can group by “quarter” to see quarterly sales, filter by “is_weekend” to compare workdays to leisure days, and even build time-of-day models using the “hour” feature. The point that I'm trying to make is: pandas doesn’t just process data, it gives you the ability to express real-world time patterns directly in your dataset. This is where data starts to feel real.
import pandas as pd
import holidays
data = {
'timestamp': pd.date_range(start='2024-01-01', end='2024-12-31', freq='7D') # every 7th day in 2024
}
df = pd.DataFrame(data)
df['timestamp'] = pd.to_datetime(df['timestamp'])
df['year'] = df['timestamp'].dt.year
df['month'] = df['timestamp'].dt.month
df['day_of_week'] = df['timestamp'].dt.day_name()
us_holidays = holidays.US()
za_holidays = holidays.ZA()
in_holidays = holidays.IN()
df['holiday_us'] = df['timestamp'].dt.date.map(lambda date: us_holidays.get(date, 'Regular Day'))
df['holiday_za'] = df['timestamp'].dt.date.map(lambda date: za_holidays.get(date, 'Regular Day'))
df['holiday_in'] = df['timestamp'].dt.date.map(lambda date: in_holidays.get(date, 'Regular Day'))
df['is_holiday_any'] = df.apply(lambda row: (
row['holiday_us'] != 'Regular Day' or
row['holiday_za'] != 'Regular Day' or
row['holiday_in'] != 'Regular Day'
), axis=1)
df['holiday_name_combined'] = df.apply(lambda row: ', '.join(
[h for h in [row['holiday_us'], row['holiday_za'], row['holiday_in']] if h != 'Regular Day']
) if row['is_holiday_any'] else 'Regular Day', axis=1)
print(df.head(20))
But, as you've already guessed it by now... people don’t behave the same way on holidays as they do on regular weekdays. A Monday that happens to be “Christmas Day” carries a completely different meaning from a regular Monday in March. And yet, many analysts miss this detail entirely. By ignoring holidays, they accidentally teach their models that all Mondays are equal (when in reality, they’re not even close) Think about it for a moment. A retail company in India sees massive sales spikes during Diwali, while one in the U.S. experiences record-breaking activity on Black Friday. Meanwhile, offices in the U.K. slow down during Easter or the Queen’s Birthday, and in South Africa, Freedom Day shifts entire patterns of service usage. These aren’t random blips in the data, but predictable cultural moments.
Source: Sahir Maharaj (https://sahirmaharaj.com)
If your model knows how to recognize them, it can forecast demand more intelligently, plan staffing better, and even optimize supply chains. That’s where the Python holidays library becomes one of the most practical yet underused tools in a data professional’s toolkit. I find that the great thing about the holidays package is thSource: Sahir Maharaj (https://sahirmaharaj.com)at it already includes prebuilt calendars for dozens of countries, so you don’t have to manually maintain date lists. You can even combine multiple regions (perfect for global datasets!).
You can see which dates overlap as holidays in multiple countries (like Christmas or New Year’s) versus those unique to specific regions (like Diwali or Juneteenth). Having this “holiday map” in your data ensures your model doesn’t confuse cultural patterns for anomalies. Once you’ve built this feature, you can take it further. For example, if you’re working on forecasting demand or staffing schedules, you might want to categorize holidays by type - religious, national, or public. That way, your model can learn not just that something special happened, but what kind of event it was.
holiday_types = {
'Christmas Day': 'Religious',
'New Year’s Day': 'Public',
'Good Friday': 'Religious',
'Diwali': 'Cultural',
'Independence Day': 'National',
'Freedom Day': 'National'
}
df['holiday_type'] = df['holiday_name_combined'].map(holiday_types).fillna('Regular Day')
print(df['holiday_type'].value_counts())
However, while holidays reflect cultural patterns, seasons capture environmental ones. Seasonality is one of the most consistent yet under-leveraged patterns in data. Whether it’s the surge of air conditioner sales in summer, ski resort bookings in winter, or agricultural yield cycles across the year, seasons are the silent drivers of demand and behavior. Unlike holidays that disrupt patterns temporarily, seasons reshape them gradually and predictably. But here’s the interesting part: seasons are relative.
Source: Sahir Maharaj (https://sahirmaharaj.com)
If you’re in the Northern Hemisphere, December means winter coats and fireplaces. In the Southern Hemisphere, it means beaches and ice cream. So if your company serves customers across continents (say, South Africa, the United States, and Australia) assuming that “December = winter” could completely break your model’s logic. To truly capture seasonal trends, your dataset needs to adapt dynamically to geography, not just date.
import pandas as pd
import numpy as np
date_range = pd.date_range(start='2021-01-01', end='2025-12-31', freq='D')
regions = ['South Africa', 'United States', 'India', 'Australia']
df = pd.DataFrame({
'timestamp': np.repeat(date_range, len(regions)),
'region': np.tile(regions, len(date_range))
})
df['timestamp'] = pd.to_datetime(df['timestamp'])
df['year'] = df['timestamp'].dt.year
df['month'] = df['timestamp'].dt.month
df['day'] = df['timestamp'].dt.day
df['day_of_year'] = df['timestamp'].dt.dayofyear
df['quarter'] = df['timestamp'].dt.quarter
def get_hemisphere(region):
northern = ['United States', 'India', 'Germany', 'China', 'France']
southern = ['South Africa', 'Australia', 'Brazil', 'Argentina']
return 'Northern' if region in northern else 'Southern'
df['hemisphere'] = df['region'].apply(get_hemisphere)
def get_season(month, hemisphere):
if hemisphere == 'Northern':
if month in [12, 1, 2]:
return 'Winter'
elif month in [3, 4, 5]:
return 'Spring'
elif month in [6, 7, 8]:
return 'Summer'
else:
return 'Autumn'
else: # Southern Hemisphere
if month in [12, 1, 2]:
return 'Summer'
elif month in [3, 4, 5]:
return 'Autumn'
elif month in [6, 7, 8]:
return 'Winter'
else:
return 'Spring'
df['season'] = df.apply(lambda row: get_season(row['month'], row['hemisphere']), axis=1)
From a data modeling perspective, seasonality adds a smooth, cyclical rhythm to otherwise chaotic datasets. Linear models, for example, struggle with repeating fluctuations unless time is represented in features like sine and cosine transformations that capture periodicity. When you encode seasons thoughtfully, you give your models the ability to “sense” time without explicitly knowing the calendar. This is crucial for forecasting, anomaly detection, and trend analysis, where understanding when something happens can be as important as what happens. Ignoring seasonality often leads to overfitting, because the model misinterprets normal, recurring cycles as random noise.
Source: Sahir Maharaj (https://sahirmaharaj.com)
And finally, the real-world value of capturing seasonality lies in decision-making, not just prediction. Businesses use seasonal patterns to adjust inventory, shift marketing spend, and manage workforce allocation. A logistics company may prepare for winter delays in the U.S. while scaling operations for summer surges in Australia. Financial analysts rely on seasonal adjustment factors to make sense of economic indicators like GDP and employment rates. Even public health models use seasonality to predict flu outbreaks or hospital admissions.
def add_transition(row):
m = row['month']
s = row['season']
if s == 'Summer' and m in [11, 3]:
return 'Pre/Post Summer'
elif s == 'Winter' and m in [5, 9]:
return 'Pre/Post Winter'
elif s == 'Autumn' and m in [2, 6]:
return 'Pre/Post Autumn'
elif s == 'Spring' and m in [8, 12]:
return 'Pre/Post Spring'
else:
return s
df['season_detailed'] = df.apply(add_transition, axis=1)
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(12, 6))
sns.countplot(data=df.sample(5000), x='season', hue='region')
plt.title('Seasonal Distribution Across Regions')
plt.xlabel('Season')
plt.ylabel('Number of Records (Sampled)')
plt.legend(title='Region', bbox_to_anchor=(1.05, 1), loc='upper left')
plt.tight_layout()
plt.show()
So, if there’s one thing you take away, let it be this: time-aware features are often the missing piece between a model that’s “good enough” and one that truly performs. The good news is that you don’t need complex tooling to get started. Whether you're building forecasting models, dashboards, or customer behavior analysis, these techniques are immediately applicable (and far more scalable than most people realize)
Here’s the challenge - don’t just bookmark this for later. Open a Microsoft Fabric notebook, load a dataset you’ve worked on before, and start extracting. Break down your dates, map the seasons, overlay holidays, and ask better questions of your data. You’ll be amazed at how quickly insights emerge when you give time the structure it deserves. And the great thing is... Microsoft Fabric is built for exactly this kind of iterative, fast feedback loop. So, go ahead - make your data time-aware, and give it the context it’s been waiting for!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.