2017-06-15 100 views
-1

如图所示,我有两个类型为datetime64 [ns]的数据帧列。我需要找到它们之间的差异。当我尝试这样做时,我收到错误。如果我试图在同一个数据框中的每一列的一个元素之间找到差异,它会给我时间增量。是否有可能丢失的东西?两个datetime64 [ns]列之间的差异显示错误

enter image description here

  • 我已经包含日期时间
  • 这些列从Int64的类型列使用pd.to_datetime()转换

--------------------------------------------------------------------------- TypeError Traceback (most recent call last) in() ----> 1 c = data['created_at'] - data['launched_at']

/home/adi/.virtualenvs/datascience/local/lib/python2.7/site-packages/pandas/core/ops.pyc in wrapper(left, right, name, na_op) 694 left, right = _align_method_SERIES(left, right) 695 --> 696 converted = _Op.get_op(left, right, name, na_op) 697 698 left, right = converted.left, converted.right

/home/adi/.virtualenvs/datascience/local/lib/python2.7/site-packages/pandas/core/ops.pyc in get_op(cls, left, right, name, na_op) 328 return _Op(left, right, name, na_op) 329 else: --> 330 return _TimeOp(left, right, name, na_op) 331 332

/home/adi/.virtualenvs/datascience/local/lib/python2.7/site-packages/pandas/core/ops.pyc in init(self, left, right, name, na_op) 341 super(_TimeOp, self).init(left, right, name, na_op) 342 --> 343 lvalues = self._convert_to_array(left, name=name) 344 rvalues = self._convert_to_array(right, name=name, other=lvalues) 345

/home/adi/.virtualenvs/datascience/local/lib/python2.7/site-packages/pandas/core/ops.pyc in _convert_to_array(self, values, name, other) 452 supplied_dtype = values.dtype 453 inferred_type = supplied_dtype or lib.infer_dtype(values) --> 454 if (inferred_type in ('datetime64', 'datetime', 'date', 'time') or 455 is_datetimetz(inferred_type)): 456 # if we have a other of timedelta, but use pd.NaT here we

TypeError: data type "datetime" not understood

作为int64类型的数据类型:

enter image description here

转换为datetime格式

enter image description here

+0

[This](https://stackoverflow.com/a/37453925/5811078)可能会有所帮助。 – zipa

+0

那里他不能在阅读csv时转换。但在这种情况下,我有需要的数据类型 –

+0

列可以请你告诉我你的数据帧,可以帮助我解决。 – ammy

回答

0

好吧,我设法做大熊猫v0.20.2的更新来解决它之后。实际上,当我使用Anaconda时,我做了一个conda update pandas,它更新了依赖于熊猫的东西(也就是说所有的东西)。