Review Publically — Header (standalone)
Working with Dates and Time Series in Pandas: A Complete Guide (2026)
Dates and time series in pandas explained: parsing, resample vs rolling, timezone localize vs convert, and what's still nanosecond after Pandas 3.0.

🐍 Python Cluster · 12 of 15 · Advanced

Working with Dates and Time Series in Pandas: A Complete Guide (2026)

Working with Dates and Time Series in Pandas starts before any of the interesting parts: a date has to actually become a date before pandas can do anything calendar-aware with it. Article 11 closed by promising the same vectorized instincts applied to a calendar. This guide delivers that, along with a resolution change this cluster has followed since Article 6, now showing up in its most direct form: the exact unit a parsed date is stored in.

by Khalid Hussain •Published Aug 16, 2026 •🕐 13 min read

Quick Answer: Dates and Time Series in Pandas

▶ Direct Answer · Dates and Time Series in Pandas

Working with dates and time series in pandas starts with pd.to_datetime(), converting text into real datetime values so .dt, resample(), and rolling() can be used on them. resample() changes the time interval data is grouped into, such as daily to weekly. rolling() keeps the original interval and smooths across a moving window instead. As of Pandas 3.0, parsing a date string defaults to microsecond resolution rather than the nanosecond precision most tutorials still describe.

us
the default unit for a parsed date string since Pandas 3.0, not the nanosecond most tutorials still describe
See What's Still Nanosecond
2
ways to smooth a time series: resample changes the buckets, rolling moves across them
Covered in full below
1
narrow case still defaulting to nanosecond: a raw, un-annotated integer epoch
Verified directly below

A Date That Isn't a Date Yet

A sales log arrives with dates stored as plain text, the way dates almost always arrive. Before anything calendar-aware can happen, that text needs to actually become a date.

pythonNOT_YET_A_DATE.PY
import pandas as pd

raw = pd.Series(["2026-01-01", "2026-01-02", "2026-01-03"])
print(raw.dtype)
# str

parsed = pd.to_datetime(raw)
print(parsed.dtype)
# datetime64[us]

That [us] is not a typo. As of Pandas 3.0, parsing a date string defaults to microsecond resolution, not the nanosecond precision older tutorials, and older pandas itself, describe as fixed. This cluster has followed that exact change since Article 6. It shows up here in its most direct form yet: the actual storage unit of a parsed date.

Timestamp, to_datetime, date_range

Three tools build almost every date a pandas script needs. pd.Timestamp() creates a single point in time:

pythonTIMESTAMP.PY
one_day = pd.Timestamp("2026-01-01 09:00:00")
print(one_day)
# 2026-01-01 09:00:00

pd.to_datetime() converts a whole column at once, the far more common case in practice. pd.date_range() builds an evenly spaced sequence of dates directly, with no source strings to parse at all:

pythonDATE_RANGE.PY
sales = pd.Series(
    [120, 135, 98, 150, 200, 210, 90, 88, 175, 160],
    index=pd.date_range("2026-01-01", periods=10, freq="D")
)

The dt Accessor

Every calendar field, year, month, day, weekday, quarter, is available through .dt, the datetime equivalent of .str for text columns:

pythonDT_ACCESSOR.PY
df = pd.DataFrame({"date": sales.index, "amount": sales.values})
df["date"].dt.day_name()
# 0     Thursday
# 1       Friday
# 2     Saturday
# ...

Resampling

resample() regroups a time series onto a new, usually coarser, interval, then applies an aggregation, sum here, though mean, max, or any groupby-style function works the same way:

pythonRESAMPLE.PY
sales.resample("5D").sum()
# 2026-01-01    703
# 2026-01-06    723
# Freq: 5D, dtype: int64

It answers a different question than a plain groupby: not by category, but by time itself.

Rolling Windows

A rolling window computes a statistic over a moving span of rows instead of fixed buckets, smoothing day to day noise into a trend:

pythonROLLING.PY
sales.rolling(3).mean()
# 2026-01-01           NaN
# 2026-01-02           NaN
# 2026-01-03    117.666667
# 2026-01-04    127.666667
# ...

The first two values come back empty since there aren't yet three days to average.

Timezones

tz_localize() declares a timezone a naive timestamp was already implicitly in, without changing the clock time itself:

pythonLOCALIZE.PY
naive = pd.Timestamp("2026-01-01 09:00:00")
aware = naive.tz_localize("UTC")
print(aware)
# 2026-01-01 09:00:00+00:00

tz_convert() does the opposite: it changes a timestamp that already knows its timezone into a different one, shifting the clock time to match:

pythonCONVERT.PY
aware.tz_convert("America/New_York")
# 2026-01-01 04:00:00-05:00
A safer default than it used to be

Mixing timezone-aware and timezone-naive values used to fail quietly in older pandas, silently converting to UTC without ever properly setting the timezone. Current pandas raises an error the moment naive and aware values meet in the same operation, catching the mistake immediately instead of letting a subtly wrong timestamp ship downstream.

What's Still Nanosecond

One case keeps the old default. Converting a raw, un-annotated integer, a Unix epoch value with no unit specified, still defaults to nanosecond, exactly as it always has:

pythonEPOCH_INT.PY
pd.to_datetime(1700000000000000000)
# unit: ns, still

Every string-based path covered above, which is the overwhelming majority of real code, moved to microsecond. This one narrow, rarely used entry point did not. Worth knowing, rarely worth worrying about.

Mistakes That Give Away a Beginner

  • Leaving a date column as plain text and being confused when .dt raises an error. Nothing works without to_datetime() first.
  • Mixing timezone-aware and timezone-naive timestamps in the same comparison or merge, and letting the resulting error interrupt a script instead of localizing everything up front.
  • Confusing tz_localize with tz_convert, shifting a clock time that should have stayed put, or leaving one untouched that should have moved.
  • Assuming resample() and rolling() do the same job. resample() changes the time buckets; rolling() smooths over the buckets that already exist.
  • Trusting a tutorial that states Timestamp is fixed at nanosecond precision. True before Pandas 3.0, no longer true for how a parsed date string is actually stored.

Practice: Fix These Three Yourself

1

Parse it, then check it

Take a Series of date strings, run to_datetime() on it, and print the resulting dtype to confirm it lands on datetime64[us].

2

Two kinds of smoothing

Using the sales series, compute a 3-day resample sum and a 3-day rolling mean, and explain in one sentence why the two results have a different number of rows.

3

Cross a timezone

Localize a naive timestamp to "UTC", convert it to "America/New_York", and check whether the calendar date changes along with the clock time.

Frequently Asked Questions

How do you convert a string column to datetime in pandas?

Call pd.to_datetime() on the column, such as df["date"] = pd.to_datetime(df["date"]). The result stores real datetime values instead of plain text, which is required before .dt, resample(), or rolling() based on dates will work.

What's the difference between resample and rolling?

resample() changes the actual time interval the data is grouped into, such as turning daily values into 5-day totals. rolling() keeps the original interval and computes a moving statistic across a window of consecutive rows instead.

What's the difference between tz_localize and tz_convert?

tz_localize() declares the timezone a naive timestamp was already implicitly in, without changing the clock time. tz_convert() changes an already timezone-aware timestamp into a different timezone, shifting the clock time to match.

Does pandas still use nanosecond precision?

Only for one narrow case, converting a raw integer epoch with no unit specified. Parsing a date string, the far more common situation, defaults to microsecond precision as of Pandas 3.0.

Why does mixing timezone-aware and naive dates raise an error?

Because there is no safe way to compare or combine a timestamp with an unknown timezone against one with a known timezone. Current pandas raises an error immediately instead of silently guessing, which older versions sometimes did.

How do you extract the day of the week from a datetime column?

Use the dt accessor: df["date"].dt.day_name() returns the weekday name for every row, and df["date"].dt.weekday returns it as a number instead, Monday as 0.

Conclusion: Text Until It Isn't

A date is only useful once pandas actually knows it's a date, not just text that happens to look like one. Everything here, resampling, rolling windows, timezones, only becomes available after that first conversion, and the exact resolution that conversion lands on has quietly changed since Article 6 first raised the question.

Practice the three exercises above, then move to the next article in this cluster, which closes out this tier and turns toward something different: the interview questions that come up again and again once the syntax itself stops being the hard part.

🐍 Continue the Python Cluster

Next Up: Python Interview Questions for Data Scientists

The questions that come up again and again, and how to actually answer them.

▶  Read the Interview Guide