这种错误很常见,主要可能是我们操作的(df)是一个dataframe,应该正确的运用索引,loc或者iloc。
例如,我遇到一次错误:
factors = data[:, :] # 其它因素
m, n = factors.shape
corrs = np.zeros((n, n))
for i in range(n):
print(i)
for j in range(n):
corrs[i, j] = dist_corr(factors[:, i], factors[:, j])
corrs
TypeError: '(slice(None, None, None), slice(None, None, None))' is an invalid key
更正后:
factors = data.iloc[:, :] # 其它因素
m, n = factors.shape
corrs = np.zeros((n, n))
for i in range(n):
print(i)
for j in range(n):
corrs[i, j] = dist_corr(factors.iloc[:, i], factors.iloc[:, j])
corrs

1万+

被折叠的 条评论
为什么被折叠?



