我想减去日期增量时间,给予大熊猫系列:从日期减去timedelta - 大熊猫
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]
可以看出,I'n已经与日期时间的工作。但是,当我尝试执行减法时,出现错误:
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')
我错过了什么?
谢谢。我虽然可以使用datetime中的timedelta函数。 – pceccon
我想如果使用'熊猫',最好是使用熊猫功能,因为熊猫开发者主要实施它们。这似乎是错误,可以创建新的[问题](https://github.com/pandas-dev/pandas/issues) – jezrael