【发布时间】:2019-03-19 17:24:27
【问题描述】:
我有日期:
dateTo=pd.to_datetime('today').strftime('%Y-%m-%d')
我想在日期列中减去dateTo:
number dates coord
AC 10 2018-07-10 11.54
AC 10 2018-07-11 11.19
AN 5 2018-07-12 69.40
所需的输出将是一个带有减法输出的新列df['datepond']。我希望这个输出是整数。
我尝试的是这里给出的回复Pandas: Subtracting two date columns and the result being an integer:
df['datepond']=(pd.Timestamp(dateTo)-pd.to_datetime(df['dates']))/ np.timedelta64(1, 'D')
在 numpy 1.12.1 版本中它工作得很好,但我现在在 numpy 1.15.2 并且它输出
TypeError: data type "datetime" not understood
我怎样才能得到想要的输出?
【问题讨论】:
-
能否提供您的错误的完整追溯?
标签: python pandas numpy datetime