python中不同日期类型值之间的相减

python中不同日期类型值之间的相减,python,python-2.7,pandas,Python,Python 2.7,Pandas,我有一个如下所示的数据帧: raw_data = {'Series_Date':['2017-03-10','2017-03-13','2017-03-14','2017-03-15'],'SeriesDate':['2017-03-10','2017-03-13','2017-03-14','2017-03-15']} import pandas as pd df = pd.DataFrame(raw_data,columns=['Series_Date','SeriesDate']) pri

我有一个如下所示的数据帧:

raw_data = {'Series_Date':['2017-03-10','2017-03-13','2017-03-14','2017-03-15'],'SeriesDate':['2017-03-10','2017-03-13','2017-03-14','2017-03-15']}
import pandas as pd
df = pd.DataFrame(raw_data,columns=['Series_Date','SeriesDate'])
print df
但是,在运行以下命令时:

from pandas.tseries.offsets import BDay
df['SeriesDate'] = pd.to_datetime(df['SeriesDate'])
df['Start_Date'] = df['SeriesDate'] - BDay(10)
我得到以下错误:

TypeError: ufunc subtract cannot use operands with types dtype('<M8[ns]') and dtype('O')

TypeError:ufunc subtract无法将操作数与类型dtype一起使用(“代码对我来说很好。因此我猜您的环境中存在一些问题。您可以在此处阅读类似的答案:


本应发表评论而不是回答,但我没有足够的代表这样做。

df['SeriesDate']=pd.to_datetime(series['SeriesDate'])df['StartDate']=df['SeriesDate']-timedelta(days=3)在我尝试这样做时打印df:df['DateDifference']=((df.StartDate-df.EndDate)/2.dt.ceil('D')我得到以下错误:TypeError:ufunc subtract不能使用dtype('D')类型的操作数