Some events occur more often at certain times of the day, for example, fraudulent activity occurs more likely during the night or early morning. Also, occasionally, organizations want to track whether an event occurred after another one, in a very short time window, for example, if sales increased on the back of displaying a TV or online advertisement. Therefore, deriving time features is extremely useful. In this recipe, we will extract different time parts of a datetime variable utilizing pandas and NumPy.
Extracting time parts from a time variable
How to do it...
To proceed with the recipe, let's import the libraries and create a toy dataset:
- Let's import pandas and NumPy:
import numpy as np
import pandas as...