【发布时间】:2017-11-30 16:22:58
【问题描述】:
我有一系列p 类型的时间戳:dtype('<M8[ns]')
我正在尝试将其转换为一周的第一天,如下所示:
p - pd.Timedelta(days=p.dt.dayofweek)
这显然不是正确的答案
TypeError: Invalid type <class 'pandas.core.series.Series'>. Must be int or float.
但是什么是?
------------完整堆栈跟踪 -----
TypeErrorTraceback (most recent call last)
<ipython-input-699-bb55f007b4d9> in <module>()
2 p= testDf.PlayDate.drop_duplicates()
3 #p=pd.to_datetime(p)
----> 4 p - pd.to_timedelta(p.dt.dayofweek, unit='D')
5
C:\DS\Installs\Anaconda3\lib\site-packages\pandas\core\ops.py in wrapper(left, right, name, na_op)
607
608 time_converted = _TimeOp.maybe_convert_for_time_op(left, right, name,
--> 609 na_op)
610
611 if time_converted is None:
C:\DS\Installs\Anaconda3\lib\site-packages\pandas\core\ops.py in maybe_convert_for_time_op(cls, left, right, name, na_op)
567 return None
568
--> 569 return cls(left, right, name, na_op)
570
571
C:\DS\Installs\Anaconda3\lib\site-packages\pandas\core\ops.py in __init__(self, left, right, name, na_op)
280 left, right = left.align(right, copy=False)
281
--> 282 lvalues = self._convert_to_array(left, name=name)
283 rvalues = self._convert_to_array(right, name=name, other=lvalues)
284
C:\DS\Installs\Anaconda3\lib\site-packages\pandas\core\ops.py in _convert_to_array(self, values, name, other)
396 supplied_dtype = values.dtype
397 inferred_type = supplied_dtype or lib.infer_dtype(values)
--> 398 if (inferred_type in ('datetime64', 'datetime', 'date', 'time') or
399 com.is_datetimetz(inferred_type)):
400 # if we have a other of timedelta, but use pd.NaT here we
TypeError: data type "datetime" not understood
【问题讨论】:
-
能否添加重现错误的数据?
标签: python-3.x pandas numpy