Finding the Weekday of a Date in Python
Determining the weekday (Monday, Tuesday, etc.) of a date is one of the most common operations in data science. It is used for creating day-of-week features, analyzing weekly seasonality, building business calendars, and generating insightful reports. In 2026, Python offers several clean and efficient ways to get the weekday of any date.
TL;DR — Recommended Methods
date.weekday()→ 0 = Monday, 6 = Sundaydate.isoweekday()→ 1 = Monday, 7 = Sundaydate.strftime("%A")→ Full day name ("Monday")- pandas
.dt.day_name()and.dt.day_of_week→ vectorized for DataFrames
1. Pure Python – datetime.date
from datetime import date
d = date(2026, 3, 19)
print(d.weekday()) # 3 → Thursday (0=Monday)
print(d.isoweekday()) # 4 → Thursday (1=Monday)
print(d.strftime("%A")) # "Thursday"
print(d.strftime("%a")) # "Thu"
2. pandas – Vectorized Weekday Extraction
import pandas as pd
# Create a small demo file so this example runs as-is
# (in your project, sales_data.csv is your real export)
import numpy as np
rng = np.random.default_rng(42)
n = 60
pd.DataFrame({
"order_id": range(1001, 1001 + n),
"order_date": pd.date_range("2026-01-01", periods=n, freq="3D"),
"customer_id": rng.integers(101, 121, n),
"customer_name": rng.choice([" ana", "ben ", "chen", "dana"], n),
"product_id": rng.integers(1, 9, n),
"region": rng.choice(["North", "South", "East", "West"], n),
"category": rng.choice(["Electronics", "Computers", "Books", "Home"], n),
"payment_method": rng.choice(["card", "cash", "wallet"], n),
"segment": rng.choice(["consumer", "business"], n),
"quantity": rng.integers(1, 6, n),
"amount": rng.uniform(50, 2500, n).round(2),
"discount": rng.choice([0.0, 0.05, 0.1, 0.2], n),
}).assign(
price=lambda d: (d["amount"] / d["quantity"]).round(2),
profit=lambda d: (d["amount"] * rng.uniform(0.05, 0.3, n)).round(2),
).assign(
ship_date=lambda d: d["order_date"] + pd.Timedelta(days=2),
status=lambda d: np.where(d["amount"] > 2000, "priority", "standard"),
).to_csv("sales_data.csv", index=False)
df = pd.read_csv("sales_data.csv", parse_dates=["order_date"])
# Add weekday features
df["weekday_number"] = df["order_date"].dt.day_of_week # 0 = Monday
df["day_name"] = df["order_date"].dt.day_name() # "Thursday"
df["day_name_short"] = df["order_date"].dt.day_name().str[:3]
df["is_weekend"] = df["order_date"].dt.day_of_week.isin([5, 6])
print(df[["order_date", "day_name", "is_weekend"]].head())
3. Real-World Data Science Examples
# Example 1: Weekly seasonality analysis
weekly_sales = df.groupby(df["order_date"].dt.day_name())["amount"].mean()
# Example 2: Business-day vs weekend filtering
business_days = df[~df["order_date"].dt.day_of_week.isin([5, 6])]
weekend_sales = df[df["order_date"].dt.day_of_week.isin([5, 6])]
4. Best Practices in 2026
- Use pandas
.dt.day_name()and.dt.day_of_weekfor large DataFrames - Prefer
.weekday()(0=Monday) for most calculations - Use
strftime("%A")only when you need the full name as a string - Always work with timezone-aware datetimes before extracting weekday
- Create
is_weekendfeature early in your pipeline
Weekday Numbering Conventions
Python offers two numbering systems. weekday() returns 0 for Monday through 6 for Sunday, while isoweekday() returns 1 for Monday through 7 for Sunday. pandas .dt.day_of_week follows the first convention.
Day names from strftime("%A") and .dt.day_name() depend on the language setting, so numbers are safer for logic and names are better for display.
Weekend flags are simply a check for 5 and 6 with the zero-based convention.
Worked Example: Weekend Flags and Ordered Day Names
We flag weekends and order a summary by weekday rather than alphabetically.
import pandas as pd
days = pd.Series(pd.date_range("2026-03-16", periods=7, freq="D"))
df = pd.DataFrame({"date": days, "orders": [12, 15, 11, 18, 22, 30, 25]})
df["dow"] = df["date"].dt.day_of_week
df["is_weekend"] = df["dow"] >= 5
df["day"] = df["date"].dt.day_name()
print(df[["day", "dow", "is_weekend"]].head(3))
summary = df.groupby(["dow", "day"])["orders"].sum().reset_index("dow", drop=True)
print(summary.index.tolist()[:3], int(df.loc[df["is_weekend"], "orders"].sum()))
16 March 2026 is a Monday, so the week starts at 0. Grouping by the number before the name keeps the days in calendar order, and the weekend orders add up to 55.
Practical Tips
For business-day logic, pandas offers bdate_range and the BDay offset, which skip weekends automatically. Custom holiday calendars can be added when national holidays also need to be excluded.
For reports read by people in different countries, prefer ISO dates such as 2026-03-16 over names of days and months, because numbers need no translation and sort correctly.
Include the weekday name only where it helps people plan, such as schedules and delivery dates.
Common Mistakes
- Mixing weekday() and isoweekday() numbers.
- Sorting day names alphabetically.
- Relying on day names for logic.
- Hard-coding locale-specific names.
Quick Summary
- weekday() starts at 0 for Monday.
- isoweekday() starts at 1.
- Use numbers for logic, names for display.
- Group by number to keep calendar order.
Conclusion
Finding the weekday of a date is simple yet extremely valuable in data science. In 2026, combine Python’s date.weekday() / strftime() with pandas’ vectorized .dt accessor to create powerful day-of-week features, analyze weekly patterns, and build smarter time-based models.
Next steps:
- Add weekday and weekend features to one of your current datasets using the patterns above