Extract Date & Time Features From a Pandas Date Column

Python
Data Preprocessing

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
2 Upvotes
Tags: Dt | Dates
Did you find this snippet useful?

Sign up to bookmark this in your snippet library

Normalize Windowed Time Series
Python
Data Preprocessing

Scaler | Normalize | Scale | Min-max

4
Pivoting Pandas Dataframes
Python
Data Preprocessing

Pandas

3
2