Dates and times
Parse, extract and resample time series data.
What you will be able to do
- Convert with pd.to_datetime.
- Use .dt for components.
- Set a datetime index for resampling.
- Store UTC and convert for display.
In plain English
Pandas datetime columns expose .dt accessors for year, month, weekday and more. Convert to a DatetimeIndex to resample by day, week or month. Always know the time zone your data is in.
import pandas as pd
df = pd.DataFrame({
'created_at': pd.to_datetime(['2026-10-01', '2026-10-02', '2026-11-01']),
'minutes': [10, 20, 15],
})
df = df.set_index('created_at')
print(df.resample('ME')['minutes'].sum())
print(df.index.month)Your turn
EasyExtract the month
Given a created_at datetime Series, add a month column.
PYTHON · starter
df['month'] =Check your understanding before moving on.
Knowledge checkQuestion 1
Which accessor exposes date parts such as .dt.month?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.