Extract Date & Time Features From a Pandas Date Column


Here we extract date and time features from a Pandas date column using dt. We extract the year, quarter, month, week, day, weekday, hour and minute.

 1|  orders['year'] = orders['Order_Date'].dt.year
 2|  orders['qtr'] = orders['Order_Date'].dt.quarter
 3|  orders['month'] = orders['Order_Date'].dt.month
 4|  orders['week'] = orders['Order_Date'].dt.week
 5|  orders['day'] = orders['Order_Date'].dt.day
 6|  orders['weekday'] = orders['Order_Date'].dt.weekday
 7|  orders['hour'] = orders['Order_Date'].dt.hour
 8|  orders['minute'] = orders['Order_Date'].dt.minute
Dt | Dates
Did you find this snippet useful?

Sign up for free to to add this to your code library