Capturing the elapsed time between datetime variables
We can extract powerful features from each datetime variable individually, as we did in the previous two recipes. We can create additional features by combining multiple datetime variables. A common example consists of extracting the age at the time of an event by comparing the date of birth with the date of the event.
In this recipe, we will learn how to capture the time between two datetime variables by utilizing pandas and feature-engine.
How to do it...
To proceed with this recipe, we’ll create a DataFrame containing two datatime variables:
- Let’s begin by importing
pandas,numpy, anddatetime:import datetime import numpy as np import pandas as pd
- We’ll start by creating two
datetimevariables with 20 values each; the values start from2024-05-17and increase in intervals of1hour for the first variable, and1month for the second. Then, we‘ll capture the variables in a DataFrame...