I would like to create a new column in my dataset, which is a difference in years between today and a another column already in the dataset, filled up with dates.
the code above:
df['diff_years'] = datetime.today() - df['some_date']
df['diff_years']
give me the following output (exemple):
1754 days 11:44:28.971615
and i have to get something like (meaning the output above in years):
4,8
(or 5)
I appreciate any help!
PS.: i would like to avoid looping the series, path i believe would give me a desired solution, but due having a big series i would like to avoid this way.
解决方案
Before some days i was facing same issue in my project now i had tried with these ,
from dateutil.relativedelta import relativedelta
from datetime import date
now = date.today()
some_date = date(df['some_date'])
rdelta = relativedelta(now, some_date)
print('diff in years - ', rdelta.years)
print('remaining months - ', rdelta.months)
print('remaining days - ', rdelta.days)
It should print difference in years