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

Pandas · Pipe

dt accessor

Series.dt is pandas’ dtype-specific accessor for datetime, timedelta, and period values. It provides vectorized date-related properties and methods such as extracting month, year, or weekday information.

How it works

Use the Series dt accessor after converting values to a pandas datetime-like dtype. It exposes calendar properties such as month and year, plus methods for date-related operations; each expression operates element by element on the Series.

Syntax

Series.dt.<property_or_method>

Returns

A datetimelike Series property or operation result; the exact result depends on the selected dt member.

Key points

  • Pandas organizes operations for specialized Series dtypes under accessors.
  • Use Series.dt to reach datetimelike values and their supported properties.
  • Properties follow the Series.dt.<property> form.

Example: Extract date components

import pandas as pd

s = pd.Series(pd.to_datetime(["2024-01-15", "2024-02-20"]))
print(s.dt.month.tolist())
print(s.dt.day_name().tolist())

The accessor extracts calendar properties and provides date-related methods from a datetime-like Series.

When to use it

Calendar feature extraction

Turn parsed timestamps into month, year, or quarter columns for reporting.

Weekday analysis

Derive weekday labels or numbers before grouping records.

Time-series preparation

Apply datetime-like formatting and transformations to a Series.

Interview questions

QWhat is the purpose of the dt accessor?

Series.dt is a dtype-specific namespace for datetimelike Series. It exposes datetime, timedelta, and period properties and operations such as month extraction and formatting.

Follow-up: What should be done when the source values are strings? Convert valid strings with pd.to_datetime before using dt.

QHow do you extract calendar information with dt?

A datetime-like Series can use expressions such as s.dt.month to obtain a component and s.dt.day_name() to obtain a derived label. These operations are vectorized over the Series.

Follow-up: How would you group records by weekday? Use a weekday-related dt property, then group or aggregate using the resulting Series.

QWhich data types does dt cover?

The accessor supports multiple datetimelike families: datetime, timedelta, and period values. The available namespace depends on the Series dtype.

Follow-up: Why can the same dt expression fail on another Series? Its dtype may not belong to a supported datetimelike family.

  • pandas.Series.dt.month
  • pandas.Series.dt.year
  • pandas.Series.dt.quarter
  • pandas.Series.dt.day_name
  • pandas.to_datetime

Source: Series — pandas documentation. Checked 2026-10-15.