DatetimeIndex

A DatetimeIndex is a pandas index made of dates and times. It allows selecting by period with text (df['2025-03']), accessing time components, resampling, and aligning series. You create it with pd.to_datetime then set_index, and you sort the index.

Example

df = df.set_index(pd.to_datetime(df['date'])).sort_index()

Related concepts

The whole glossary