Capturing the elapsed time between datetime variables
datetime
variables offer value individually, though they may offer additional value collectively when used with other datetime
variables to derive important insights. A common example consists of deriving the age at the time of an event from the date of birth and date of event variables. We can combine several datetime
variables to derive the time that has passed and create more meaningful features. In this recipe, we will learn how to capture the time between two datetime
variables in different formats and the time between a datetime
variable and the current time by utilizing pandas, NumPy, and the datetime
library.
How to do it...
To proceed with this recipe, we must import the necessary libraries and create a toy dataset:
- Let’s begin by importing
pandas
,numpy
, anddatetime
:import datetime import numpy as np import pandas as pd
- Let’s create two
datetime
variables with 20 values each, in which values...