无法根据规则'same_kind'从元数据[Y]到[D]转换datetime.timedelta对象

时间:2017-11-26 03:52:16

标签: python-3.x

我的代码如下:

import pandas as pd
import quandl as qdl
from scipy.stats import linregress

# get AAPL 10 years data

data = qdl.get("WIKI/AAPL", start_date="2011-01-01", end_date="2017-05-01")

data0 = data.copy()
data0['date_id'] = ((data0.index.date - data0.index.date.min())).astype('timedelta64[D]')

但是当我运行它时出现以下错误:

TypeError: Cannot cast datetime.timedelta object from metadata [Y] to [D] according to the rule 'same_kind'

1 个答案:

答案 0 :(得分:0)

from datetime import datetime

data0['date_id'] = ((data0.index.date - data0.index.date.min())).astype(datetime)