Deriving representations of the year and month

Some events occur more often at certain times of the year, for example, recruitment rates increase after Christmas and slow down toward the summer holidays in Europe. Businesses and organizations want to evaluate performance and objectives at regular intervals throughout the year, for example, at every quarter or every semester. Therefore, deriving these features from a date variable is very useful for both data analysis and machine learning. In this recipe, we will learn how to derive the year, month, quarter, and semester from a datetime variable using pandas and NumPy.

Get Python Feature Engineering Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.