我的代码如下:
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'
答案 0 :(得分:0)
from datetime import datetime
data0['date_id'] = ((data0.index.date - data0.index.date.min())).astype(datetime)