Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Module

.dt.weekday

Extracts the ISO weekday number from Date or Datetime expressions. Monday is 1 and Sunday is 7, and the result has Int8 data type.

How it works

Call dt.weekday() on a date- or datetime-valued expression to produce the ISO weekday number for each value. The result is an Int8 expression, with Monday represented by 1 and Sunday by 7; it can be added to a DataFrame using with_columns.

Syntax

Expr.dt.weekday() → Expr

Returns

Expr of data type Int8 containing the ISO weekday number for each Date or Datetime value.

Key points

  • The method derives the weekday from the underlying date representation.
  • It supports both Date and Datetime columns.
  • The numbering is ISO-based: Monday maps to 1 and Sunday maps to 7.
  • The returned expression has the Int8 data type.
  • The method takes no arguments and returns an Expr.

Common mistakes

  • The expression must operate on a Date or Datetime column; other logical data types are outside the documented applicability.

Example: Extract ISO weekdays

import polars as pl
from datetime import date

df = pl.DataFrame({"date": [date(2024, 1, 1), date(2024, 1, 7)]})
result = df.with_columns(
    pl.col("date").dt.weekday().alias("weekday")
)
print(result)

Adds an ISO weekday-number column: Monday is 1 and Sunday is 7.

When to use it

Calendar-based aggregation

Add a numeric weekday column for grouping or reporting.

Weekend and weekday filtering

Filter records to weekdays or weekends.

Temporal feature engineering

Build weekday features for analytics or machine-learning pipelines.

Interview questions

QWhat does Expr.dt.weekday() return?

Expr.dt.weekday() extracts the ISO weekday from a Date or Datetime expression. It returns an Expr whose data type is Int8, using 1 for Monday through 7 for Sunday.

Follow-up: How would you retain the original date while adding the weekday? Use with_columns(pl.col("date").dt.weekday().alias("weekday")).

QWhat numbering convention does it use?

The output follows ISO weekday numbering: Monday is 1 and Sunday is 7. This makes weekday comparisons independent of locale-specific Sunday-first numbering.

Follow-up: How would you select weekend rows? Filter where the derived weekday is greater than 5, such as pl.col("date").dt.weekday() > 5.

QHow is this method typically used in a DataFrame transformation?

It is an expression method, so it is evaluated as part of a Polars expression pipeline rather than immediately extracting one scalar. It can therefore be used in transformations such as with_columns and filter.

Follow-up: What output type should downstream code expect? An Int8 expression, not a string containing a weekday name.

  • Expr.dt.day
  • Expr.dt.week
  • Expr.dt.ordinal_day
  • Series.dt.weekday

Source: polars.Expr.dt.weekday — Polars documentation. Checked 2026-10-15.