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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.