在以下示例中:
import datetime
import pandas
base = datetime.datenow()
rr = [base - datetime.timedelta(days=x) for x in range(23)]
ee = [base - datetime.timedelta(days=x+3) for x in range(23)]
qq = pandas.DataFrame(data=rr, index=ee, columns=['datacol'])
qq.index - qq.datacol.values
最后一行引发了一个 TypeError:
In [11]: qq.index-qq.datacol.values
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-e850e726adac> in <module>()
----> 1 qq.index-qq.datacol.values
/usr/local/lib/python2.7/dist-packages/pandas/tseries/index.pyc in __sub__(self, other)
556 return self.shift(-other)
557 else: # pragma: no cover
--> 558 raise TypeError(other)
559
560 def _add_delta(self, delta):
TypeError: ['2013-11-08T21:18:50.478689000-0800' '2013-11-07T21:18:50.478689000-0800'
如何获得索引和列之间的差异?
注意:来自日期时间对象,但索引自动成为时间戳。