【发布时间】:2021-01-25 14:36:29
【问题描述】:
我一直在尝试使用 python 绘制股票随时间的成对相关性。我正在关注以下repository,但我似乎无法使滚动相关工作,我在这里收到错误:
correls = correls[(window-1):,:,:]
TypeError: '(slice(99, None, None), slice(None, None, None), slice(None, None, None))' is an invalid key
添加示例代码:
todays_date = datetime.datetime.now().date()
index = pd.date_range(todays_date, periods=10, freq='D')
columns = ['A', 'B', 'C']
df = pd.DataFrame(index=index, columns=columns)
df = df.mask(df.isnull(), np.random.uniform(3, 331, size=df.shape))
window = 2 #rolling correlation window length
correls = df.rolling(window=window).corr()
correls = correls[(window-1):,:,:]
亲切的问候
【问题讨论】:
-
您能否发布您使用的示例数据框和示例代码。谢谢。