我正在尝试从给定的Pandas系列中减去delta时间。
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]
可以看到,我已经在使用日期时间了。但是,当我尝试执行减法时,出现了错误:
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')
我漏掉了什么?
pandas
,最好使用pandas函数,因为pandas开发人员主要实现它们。这里似乎有一个错误,可以创建新的问题。 - jezrael