1
我有一個熊貓數據框與兩個'日期時間'列t1,t2。現在我需要在數據幀過濾掉所有行,其中T1 < = T2 T2可以 熊貓過濾日期時間列不包括
之前熊貓0.19.0 我能做到這一點楠
:熊貓0.19.0這個代碼後import pandas as pd
from datetime import datetime
dt = datetime.utcnow()
dt64 = np.datetime64(dt)
df = pd.DataFrame([(dt64,None)], columns=['t1','t2'])
df[(df.t1<=df.t2)]
失敗
Traceback (most recent call last):
File "workspace/python/MyTests/test1.py", line 87, in <module>
testDfTimeCompare()
File "workspace/python/MyTests/test1.py", line 80, in testDfTimeCompare
df[(df.t1<=df.t2)]
File "anaconda/lib/python2.7/site-packages/pandas/core/ops.py", line 813, in wrapper
return self._constructor(na_op(self.values, other.values),
File "anaconda/lib/python2.7/site-packages/pandas/core/ops.py", line 787, in na_op
y = y.view('i8')
File "anaconda/lib/python2.7/site-packages/numpy/core/_internal.py", line 367, in _view_is_safe
raise TypeError("Cannot change data-type for object array.")
TypeError: Cannot change data-type for object array.
實現此目的的最佳方法是什麼?