Pandas .dt accessor: Extracting year, hour, and day_of_week

Pandas .dt accessor: Extracting year, hour, and day_of_week

Want to grab a part of datetime value in a Python Pandas data frame column? Use “dt”:

df['x'].dt.year
df['x'].dt.hour
df['x'].dt.minute
df['x'].dt.day_of_week  # or dayofweek or weekday

day_of_week returns an integer, where 0 is Monday and 6 is Sunday.