Have you worked on dates in python? Have you tried to find difference between the dates?
So this is the recipe on how we can calculate difference between Dates in Python.
import pandas as pd
We have only imported pandas which is needed.
We have created a data frame with Time stamp on which we will perform the operation.
df = pd.DataFrame()
df["Date1"] = [pd.Timestamp("01-01-2017"),
pd.Timestamp("01-04-2017")]
df["Date2"] = [pd.Timestamp("01-01-2017"),
pd.Timestamp("01-06-2017")]
We are using two methods for better understanding, one by directly finding the difference and another by using delta function on the two features.
print(df["Date2"] - df["Date1"])
print(pd.Series(delta.days for delta in (df["Date2"] - df["Date1"])))
So the output comes as
0 0 days 1 2 days dtype: timedelta64[ns] 0 0 1 2 dtype: int64