I have a datetime column as below -
>>> df['ACC_DATE'].head(2) 538 2006-04-07 550 2006-04-12 Name: ACC_DATE, dtype: datetime64[ns]
Now, I want to subtract an year from each row of this column. How can I achieve the same & which library can I use?
The expected field -
ACC_DATE NEW_DATE 538 2006-04-07 2005-04-07 549 2006-04-12 2005-04-12
You can use DateOffset to achieve this:
DateOffset
In[88]: df['NEW_DATE'] = df['ACC_DATE'] - pd.DateOffset(years=1) df Out[88]: ACC_DATE NEW_DATE index 538 2006-04-07 2005-04-07 550 2006-04-12 2005-04-12
1.4m articles
1.4m replys
5 comments
57.0k users