Subtracting timedelta from date - pandas

Viewed 6676

I'm trying to subtract delta times from dates, given a pandas series.:

date_current = hh.groupby('group').agg({'issue_date' : [np.min, np.max]})
date_current.issue_date.amax.head(5)

group
_101000000000_0.0   2017-01-03
_102000000000_1.0   2017-02-23
_102000000000_2.0   2017-03-20
_102000000000_3.0   2017-10-01
_103000000000_4.0   2017-01-24
Name: amax, dtype: datetime64[ns]

As can be seen, I'n already working with date times. However, when I try to perform the subtraction, I get an error:

import datetime
months = 4
datetime.timedelta(weeks=4*months)
date_before = date_current.values - datetime.timedelta(weeks=4*months)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-51-5a7f2a09bab6> in <module>()
      2 months = 4
      3 datetime.timedelta(weeks=4*months)
----> 4 date_before = date_current.values - datetime.timedelta(weeks=4*months)

TypeError: ufunc subtract cannot use operands with types dtype('<M8[ns]') and dtype('O')

What am I missing?

2 Answers
Related