我正在设置一个带有两个日期时间列的 DataFrame,如下所示:
range1 = Series(date_range('1/1/2011', periods=50, freq='D'))
range2 = Series(date_range('2/5/2011', periods=50, freq='D'))
df1 = DataFrame({'a': rng1, 'b': rng2}, dtype='datetime64[D]')
奇怪的是,询问 df1 的 dtypes 给了我:
In [71]: df1.dtypes
Out[71]:
a datetime64[ns]
b datetime64[ns]
更糟糕的是,当我尝试像这样过滤数据框时:
In [62]:
d = datetime(2011,1,14)
df1[df1 > d]
我收到一个错误:
TypeError Traceback (most recent call last)
<ipython-input-62-50b4b9735157> in <module>()
1 d = datetime(2011,1,14)
----> 2 df1[df1 > d]
/usr/local/lib/python2.7/site-packages/pandas/core/frame.pyc in f(self, other)
313 return self._combine_series_infer(other, func)
314 else:
--> 315 return self._combine_const(other, func)
316
317 f.__name__ = name
/usr/local/lib/python2.7/site-packages/pandas/core/frame.pyc in _combine_const(self, other, func)
3677 return self
3678
-> 3679 result_values = func(self.values, other)
3680
3681 if not isinstance(result_values, np.ndarray):
TypeError: can't compare datetime.datetime to long
谁能告诉我为什么会这样?我正在使用 numpy 1.7 和 pandas 0.10.1。