I have a series p
of timestamps of type: dtype('<M8[ns]')
I am trying to convert it to the first day of the week like so:
p - pd.Timedelta(days=p.dt.dayofweek)
This clearly is not the right answer
TypeError: Invalid type <class 'pandas.core.series.Series'>. Must be int or float.
but what is?
------------Full stack trace -----------------
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