Datetime (.dt) Accessor#
Access datetime methods on Series with datetime data via .dt.
Example#
import pandasCore as pd
s = pd.Series(pd.date_range('2023-01-01', periods=3))
s.dt.year # [2023, 2023, 2023]
s.dt.month # [1, 1, 1]
s.dt.dayofweek # [6, 0, 1]
Attributes#
Attribute |
Description |
|---|---|
year |
Year component |
month |
Month component |
day |
Day component |
hour |
Hour component |
minute |
Minute component |
second |
Second component |
microsecond |
Microsecond component |
nanosecond |
Nanosecond component |
dayofweek |
Day of week (Monday=0) |
dayofyear |
Day of year |
quarter |
Quarter (1-4) |
is_month_start |
Is first day of month |
is_month_end |
Is last day of month |
is_quarter_start |
Is first day of quarter |
is_quarter_end |
Is last day of quarter |
is_year_start |
Is first day of year |
is_year_end |
Is last day of year |
is_leap_year |
Is leap year |
tz |
Timezone |
freq |
Frequency |
Methods#
Method |
Description |
|---|---|
normalize() |
Set time to midnight |
strftime(format) |
Format as string |
round(freq) |
Round to frequency |
floor(freq) |
Floor to frequency |
ceil(freq) |
Ceiling to frequency |
tz_localize(tz) |
Localize to timezone |
tz_convert(tz) |
Convert to timezone |
to_period(freq) |
Convert to Period |
to_pydatetime() |
Convert to datetime |