1 Upvote

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.

orders['year'] = orders['Order_Date'].dt.year
orders['qtr'] = orders['Order_Date'].dt.quarter
orders['month'] = orders['Order_Date'].dt.month
orders['week'] = orders['Order_Date'].dt.week
orders['day'] = orders['Order_Date'].dt.day
orders['weekday'] = orders['Order_Date'].dt.weekday
orders['hour'] = orders['Order_Date'].dt.hour
orders['minute'] = orders['Order_Date'].dt.minute

By analyseup - Last Updated Jan. 13, 2022, 12:08 a.m.

Did you find this snippet useful?

Sign up to bookmark this in your snippet library

COMMENTS
RELATED SNIPPETS
Pivoting Pandas Dataframes
Python
Data Preprocessing

Pandas

3
SparkSession instantiate
Python
Data Preprocessing

2
Converting Data Types
Python
Data Preprocessing

Data-cleaning

2
Data Minification
Python
Data Preprocessing

Cleaning

2
Top Contributors
75